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

How do I locate Humanoid in this script ?

Asked by 2 years 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 2 years 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 — 2y
0
also is it a localscript or a server script? Mathilinium 112 — 2y
0
server script monstermarwan -3 — 2y
Ad
Log in to vote
0
Answered by 2 years ago
local humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
0
This is in a local script, btw. RazorXX2 24 — 2y
Log in to vote
0
Answered by
NGC4637 602 Moderation Voter
2 years 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