Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Tan0ak 28
4 years ago

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

0
Why not make it inside the tool Pupppy44 671 — 4y
0
its because then i get an error saying Players.Tan0ak.Backpack.ClassicSword.BlockingScript:6: attempt to index nil with 'Humanoid' Tan0ak 28 — 4y

2 answers

Log in to vote
0
Answered by
zadobyte 692 Moderation Voter
4 years ago

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()
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. Tan0ak 28 — 4y
0
have you tried wait for child? zadobyte 692 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

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

Answer this question