Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Handle is not a valid member of tool?

Hi, I'm currently making a sword and I have a problem where Handle is not a valid member of tool when it clearly is. Is it maybe due to a Roblox update which broke it because it has worked before and I have not changed the script in anyway. Please help

Local Script:

script.Parent.Equipped:Connect(function()
local idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Parent.Animations.Idle)
idle:Play()
script.Parent.Unequipped:Connect(function()
idle:Stop()
end)
end)


local UserInputService = game:GetService("UserInputService")
local Tool = script.Parent
local CanAttack = true
local Anim_Name = "Attack"
local Audio = script.Parent.Handle.Swing
local Attack_Animations = script.Parent:WaitForChild("Animations")
local Attack_Num = 1
local blade = script.Parent.SwordBlade

blade.Touched:Connect(function(hit)
	if CanAttack == false then
		game.ReplicatedStorage.Damage:FireServer(hit)
	end
end)

UserInputService.InputBegan:Connect(function(InputObject)
	if InputObject.UserInputType == Enum.UserInputType.MouseButton1 then
		local Animation = script.Parent.Parent.Humanoid:LoadAnimation(Attack_Animations[Anim_Name..Attack_Num])
		if CanAttack == true then
            CanAttack = false
			Animation:Play()
			Audio.PlaybackSpeed = math.random(0.9,1.1)
			Audio:Play()
			blade.Trail.Enabled = true
			wait(0.5)
			CanAttack = true
			blade.Trail.Enabled = false
			if Attack_Num == 1 then
				Attack_Num = Attack_Num + 1
				else if Attack_Num == 2 then
					Attack_Num = 1
				end
			end
		end
	end
end)

2 comments

0

What line is it erroring at?

0

Line 14

1 answer

✓ Accepted answer

This is probably because the handle doesnt exist yet. Use WaitForChild so that the script waits until the handle is found.

You should always use WaitForChild because the scripts start when the game starts, or when they are cloned. They might start before the actual parts and stuff in the world/tool/something exist.

local Audio = script.Parent:WaitForChild("Handle"):WaitForChild("Swing")

This discussion is preserved as it was. New answers, comments, and votes are closed.