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

Getting an error when trying to change a player's Character name?

I made a script that changes a random player's Character name but I'm getting an error when it gets to the name change part of my code.

The script

local players = game.Players:GetChildren()
			local hunter = players[math.random(1)]
			hunter.Character.Name = "The Hunter - Watch out!"

3 answers

✓ Accepted answer

Modifying a player's character name will result in an error. If you want to display text above someone's head, you can use BillboardGuis instead.

Also, right now it'll always pick the first player that joined the game instead of a random one, so instead of doing math.random(1), you can do math.random(1, #players).

Hope this helped

Edit: The Humanoid object has a DisplayName property, so if you're lazy and can't be bothered to make a BillboardGui you can just use that.

5 comments

0

Yep, it now works! Thanks for the help!

0

bruh very bad solution I downvoted 10 times

0

E

0

E

0

69

local players = game.Players:GetChildren()
            local hunter = players[math.random(1,1)] -- the ending number
            hunter.Character.Name = "The Hunter - Watch out!"

2 comments

0

Still getting the same error (The current identity (2) cannot set a Character's name (lacking permission 4) )

0

^ Errors are useful, listening to them can get you very far. This means that you can't set a Character's name.

Oh right you are getting an error because you have not included a second value in math.random. Let me fix this script for you:

local players = game.Players:GetChildren()
local hunter = players[math.random(1, #players)]
hunter.Character.Humanoid.Name = "The Hunter - Watch out!" -- The humanoid actually stores the name of the character silly mistake.

I don't know if this script will work, but try it out.

2 comments

0

I'm not getting an error anymore but the name doesn't show up on the random player, I've searched a bit and then found out that the Humanoid got the name changed instead of the actual player's Character which controls the name displayed above the player's head.

0

"The humanoid actually stores the name of the character silly mistake." This isn't true whatsoever, there is absolutely no reason for changing the Humanoid's name except for messing up scripts.

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