Ad
Log in to vote
0

How do I locate Humanoid in this script ?

Asked by 5 months ago
local USI = game:GetService("UserInputService")
local damage = 50
local Handle = script.Parent.Handle
local rep = game.ReplicatedStorage
local CanSprint = rep.BoolValues.CanSprint

script.Parent.Equipped:Connect(function(equip)
    local plr = equip.Parent
    local Humanoid = plr:FindFirstChild("Humanoid")

    Handle.Transparency = 1

    USI.InputBegan:Connect(function(input)
        local keycode = input.KeyCode 
        if keycode == Enum.KeyCode.F then
            Handle.Transparency = 0
            Humanoid.WalkSpeed = 40
            CanSprint = false

        end
    end)

    USI.InputEnded:Connect(function(input)
        local keycode = input.KeyCode
        if keycode == Enum.KeyCode.F then
            Handle.Transparency = 0
            Humanoid.WalkSpeed = 16
            CanSprint = true
        end

    end)

end)

3 answers

Log in to vote
0
Answered by 5 months ago

Instead of

local plr = equip.Parent
local Humanoid = plr:FindFirstChild("Humanoid")

try doing

local plr = game:GetService("Players").LocalPlayer
local Humanoid = plr.Character:FindFirstChild("Humanoid")
0
didnt work :( monstermarwan -3 — 5mo
0
also is it a localscript or a server script? Mathilinium 37 — 5mo
0
server script monstermarwan -3 — 5mo
Ad
Log in to vote
0
Answered by 5 months ago
local humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
0
This is in a local script, btw. RazorXX2 12 — 5mo
Log in to vote
0
Answered by
NGC4637 587 Moderation Voter
5 months ago

try doing this:

script.Parent.Equipped:Connect(function()
    local plr = script.Parent.Parent
    local Humanoid = plr:WaitForChild("Humanoid",0.1)
    -- rest of your code here
end)

Answer this question