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

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

Asked by
D4_rrk 89
4 years ago

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

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

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.

0
Yep, it now works! Thanks for the help! D4_rrk 89 — 4y
0
bruh very bad solution I downvoted 10 times starmaq 1290 — 4y
0
E starmaq 1290 — 4y
0
E starmaq 1290 — 4y
0
69 starmaq 1290 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
local players = game.Players:GetChildren()
            local hunter = players[math.random(1,1)] -- the ending number
            hunter.Character.Name = "The Hunter - Watch out!"
0
Still getting the same error (The current identity (2) cannot set a Character's name (lacking permission 4) ) D4_rrk 89 — 4y
0
^ Errors are useful, listening to them can get you very far. This means that you can't set a Character's name. brokenVectors 525 — 4y
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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.

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. D4_rrk 89 — 4y
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. brokenVectors 525 — 4y

Answer this question