I don't know why its happening but when I try to do repeat wait() until plr.Character.Humanoid,
it says Humanoid is not a member of Model.
My script:
plr = game.Players.LocalPlayer while true do wait() if plr.Character.Humanoid then plr.Character.Humanoid.Name = "antireset" elseif plr.Character.antiresetk then print("v") end end
There's a method you can use called WaitForChild
to wait until the Humanoid becomes available.
What's WaitForChild?
WaitForChild does exactly what it says on the tin. The script yields (waits) until the child you specify becomes available. That way, there's no issues in other parts of the script where you need to reference that child.
Here's an example of how to use this method:
plr = game.Players.LocalPlayer plr.Character:WaitForChild("Humanoid")
Optimizing your code:
Right now, you're using an infinite loop to do what you're trying to do. However, there's a much easier way to do what you're trying to do. You can use a combination of two events called PlayerAdded and CharacterAdded to make it so the player's humanoid always changes name when their character is added or respawned. Plus, you don't need multiple scripts that are replicated to each player, it's all handled in one script.
Firstly, make a new script in ServerScriptService. Then, you'll want to do the following:
game.Players.PlayerAdded:connect(function(plr) --Anonymous function for getting the player when they enter. plr is the variable for each player that's added. plr.CharacterAdded:connect(function(char) --Anonymous function for getting the player's character when it's added or respawned. char is the variable for the player's character. char:WaitForChild("Humanoid").Name = "antireset" --Waits for the humanoid and changes it's name. end) end) --The reason the ends have a closing parenthesis (bracket) around them is to close the function of each anonymous function.
Bare in mind that the PlayerAdded event does not work in Play Solo. I would suggest starting up a local Test Server (it's under the Test tab in Studio) to see if it works.
You can get rid of the comments, but they are there to show you how the script works. I hope this helps you.
Read more on anonymous functions here.
The issue is most-likely related to most-likely that the script is referring or pointing to the character's humanoid before it is added as a descendant of Character
.
You would most likely want to use WaitForChild
, which returns the child with the name matching that of its argument whenever found... until then? It yields the current thread (aka, waits)
CharacterAdded:Wait()
is also pretty similar to WaitForChild
in the sense that it waits until the event triggers or triggers again and returns whatever result is given from the event.
I also used the Changed
event, which fires every time a property of the object (Character) changes.
In this context, it checks for a change in the status of antiresetk
, which I assume is a boolean, and then proceeds to rename the Humanoid accordingly.
local player = game.Players.LocalPlayer local character = player.Character or player.CharacterAdded:wait() local humanoid = character:WaitForChild('Humanoid') local antiReset = character:WaitForChild('antiresetk') character.Changed:connect(function (property) if not (antiReset) then humanoid.Name = 'antireset' end end)