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

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

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

✓ Accepted answer

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!

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)


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