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

Why Is Tool.Equipped not working inside of starter character scripts?

So I have this code that only runs if the sword is equipped but it doesnt seem to sense if the sword is in hand. Help?

local UIS = game:GetService('UserInputService')
local plr = game.Players.LocalPlayer
local Char = plr.Character
local BlockAnim = script:WaitForChild('BlockAnim')
local Keydown = false
local Hum = Char.Humanoid
local Anim = Hum:LoadAnimation(BlockAnim)
local tool = game.StarterPack.ClassicSword
local ToolEquip = false

tool.Equipped:Connect(function()
	ToolEquip = true
end)

tool.Unequipped:Connect(function()
	ToolEquip = false
end)

UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.Q then
		Keydown = true

	end
	while Keydown == true and ToolEquip == true do
		wait(.1)
		Anim:Play()
	end
end)

UIS.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.Q then
		Keydown = false
	end
	while Keydown == false do
		wait(.1)
		Anim:Stop()
	end
end)


this is was all in a local script and is inside of starter character scripts

2 comments

0

Why not make it inside the tool

0

its because then i get an error saying Players.Tan0ak.Backpack.ClassicSword.BlockingScript:6: attempt to index nil with 'Humanoid'

2 answers

It's probably because you accessing the tool through starterpack. You should just make the local script a child of the tool and change Char to

local Char = plr.Character or plr.CharacterAdded:Wait()

2 comments

0

so i put the local script in to the classic sword tool as a child and changed the Char as u said but i got an error saying :Humanoid is not a valid member of model.

0

have you tried wait for child?

put the script inside the tool and do the same thing with the guy who helped you

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