Тулскрипт
local tool = script.Parent
tool.Activated:Connect(function()
local character = tool.Parent
if not character or character:IsA("Tool") then return end
local humanoid = character:FindFirstChildOfClass("Humanoid")
if not humanoid then return end
local hitPart = game.Players.LocalPlayer.Character:FindFirstChild("RightHand")
if not hitPart then return end
local raycastParams =
RaycastParams.new ()
raycastParams.FilterDescendantsInstances = {character}
local rayOrigin = hitPart.Position
local rayDirection = (hitPart.CFrame.LookVector * 5)
local result = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
if result and result.Instance then
print("Hit: " ..
result.Instance.Name )
-- Здесь можно добавить код для нанесения урона или других действий
end
end)
Локалскрипт
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
script.Parent.Equipped:Connect(function()
mouse.Icon = "rbxassetid://path/to/sword/icon" -- Замените на путь к вашему значку
mouse.KeyDown:Connect(function(key)
if key == "q" then -- Кнопка для атаки
script.Parent:Activate()
end
end)
end)
script.Parent.Unequipped:Connect(function()
mouse.Icon = ""
end)
Посмотри в скрипте меч активирован?
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
if player.leaderstats.Gems.Value >= 0 then
player.leaderstats.Gems.Value = player.leaderstats.Gems.Value - 0
local clonar = game.ReplicatedStorage.Tools.ClassicSword:Clone()
clonar.Parent = player.Backpack
wait(0.1) -- Добавляем небольшую задержку
clonar:Activate()
-- Активация меча после получения
clonar.Equipped:Connect(function()
print("Меч активирован")
-- Добавьте здесь дополнительные настройки или функции для меча, если необходимо
end)
end
end)
И проверь свойства меча
clonar.CanBeDropped = true
clonar.Enabled = true
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
if player.leaderstats.Gems.Value >= 0 then
player.leaderstats.Gems.Value = player.leaderstats.Gems.Value - 0
local clonar = game.ReplicatedStorage.Tools .ClassicSword:Clone()
clonar.Parent = player.Backpack
end
end)