This is probably a stupid question with a simple answer but my game has tools that need the humanoid to function. It works perfectly fine on the first life but after you reset and respawn, you get the error “Infinite yield possible on youruser:WaitForChild(“Humanoid”)”. I have no clue why it’s doing this, any help would be appreciated.
Down below is a little snippet of my code
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
thats because your only declaring the character variable once instead of updating that variable to update everytime the player respawns
rewrite your to code to be like this
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
Player.CharacterAdded:Connect(function(character)
Character = character
end)
this issue wouldnt happen in the first place if you had put the script in startercharacterscripts or starterplayerscripts or starterpack as those replicate to the character everytime they respawn automatically
That hierarchy explains the issue - the LocalScript (ClientStuff) is nested inside Motor6DTest which is a tool, so it’s not directly in the tool root. When the player respawns the script restarts and Player.Character is still the old dead one.
The Equipped fix still applies, just make sure the path to the character is correct since the script is nested deeper:
local tool = script.Parent.Parent -- Motor6DTest
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Character
local Humanoid
tool.Equipped:Connect(function()
Character = tool.Parent
Humanoid = Character:WaitForChild("Humanoid")
end)
you MIGHT be ai (also the tool is literally script.Parent anyways, unless the script is placed inside ClientStuff)
(edit: i wasnt wrong, youre John AI himself)
i dont know whats going on but this issue wont persist if the script is a descendant of starterpack or startercharacterscripts or starter playerscripts but it can be another script making that issue
if you cannot find the solution just do what i said before
May I get a basic summary on what the character creation script does? Also, if the script is in a StarterPack tool, it should be giving you a new variant of that tool everytime you respawn.
In addition, if the script is in a tool, you can get the Humanoid by using script.Parent.Parent:FindFirstChild("Humanoid").