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

How would I find the Humanoid of a local player in my script?

Asked by 7 years ago

This is my script;

local part = script.Parent

part.Touched:connect(function()
    local chance = math.random(1,100)
    if chance > 1 and chance < 40 then
        game.Players.LocalPlayer:WaitForChild("Humanoid").Walkspeed = 0
        game.Players.LocalPlayer.PlayerGui.BattleGuiTest:WaitForChild("IntroTop"):TweenPosition(UDim2.new(0, 0,0, 0),'Out','Bounce',3.5)
        game.Players.LocalPlayer.PlayerGui.BattleGuiTest:WaitForChild("IntroBottom"):TweenPosition(UDim2.new(0, 0,0, 200),'Out','Bounce',3.5)
        wait(5)
        game.Players.LocalPlayer.PlayerGui.BattleGuiTest:WaitForChild("BattleBackGround").Visible = true
        wait(0.5)
        --Might add functions
        game.Players.LocalPlayer.PlayerGui.BattleGuiTest:WaitForChild("IntroTop"):TweenPosition(UDim2.new(0, 0,-1, 0),'In','Bounce',3.5)
        game.Players.LocalPlayer.PlayerGui.BattleGuiTest:WaitForChild("IntroBottom"):TweenPosition(UDim2.new(0, 0,0, 600),'In','Bounce',3.5)
    end
end)

The error is infinite yield so basically can't find it, how would I find the Humanoid of the player? This line here: game.Players.LocalPlayer:WaitForChild("Humanoid").Walkspeed = 0

Please help, I need to find the humanoid

2 answers

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

If i'm not mistaken of what your asking, you just want to find the humanoid? If so this is what you would say:

vPlayer = game.Players.LocalPlayer
character = vPlayer.Character
humanoid = character:FindFirtChild('Humanoid') -- This should detect the humanoid of the player

you always want to make sure your a little more specific so you can make your coding a bit nicer & Neater! Hope this helped!

Ad
Log in to vote
0
Answered by 7 years ago
local part = script.Parent
local player = game.Players.LocalPlayer
local char = player.Character
local hum = char.Humanoid

part.Touched:connect(function()
    local chance = math.random(1,100)
    if chance > 1 and chance < 40 then
        hum.Walkspeed = 0
        player.PlayerGui.BattleGuiTest:WaitForChild("IntroTop"):TweenPosition(UDim2.new(0, 0,0, 0),'Out','Bounce',3.5)
        player.PlayerGui.BattleGuiTest:WaitForChild("IntroBottom"):TweenPosition(UDim2.new(0, 0,0, 200),'Out','Bounce',3.5)
        wait(5)
        player.PlayerGui.BattleGuiTest:WaitForChild("BattleBackGround").Visible = true
        wait(0.5)
        --Might add functions
        player.PlayerGui.BattleGuiTest:WaitForChild("IntroTop"):TweenPosition(UDim2.new(0, 0,-1, 0),'In','Bounce',3.5)
        player.PlayerGui.BattleGuiTest:WaitForChild("IntroBottom"):TweenPosition(UDim2.new(0, 0,0, 600),'In','Bounce',3.5)
    end
end)


Answer this question