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

My billboard gui script is not working..?

Alright so I want to do something Similar to TMM, but only to see if I can I dont want to make a knock-off game Lol.

Anyways the script isn't working and yeah... Anyhow here is the script.

local amy = script.Amy.BillboardGui
local sarah = script.Sarah.BillboardGui
local joey = script.Joey.BillboardGui
local names = {joey, sarah, amy}

game.Players.PlayerAdded:connect(function(plr)
 plr.Name = " "
for _,v in pairs(names)do
x = math.random(v:Clone())
x.Parent = plr.Character:findFirstChild("Head")
end
end)

1 comment

1

Please tell us what you want to do. This script right now tells me NOTHING!

1 answer

✓ Accepted answer

I assume you would've got an error similar to this: "bad argument #1 to 'random' (number expected, got nil)"

math.random(min,max) --Numerical values.

can only be used on numerical values, not userdata objects. In order to select a random object from an array you'd have to specify a number range for the amount of objects in the table. Using #names will return how many objects are in the array, therefore

math.random(1,#names) --Must always start with 1 as no array object is positioned as 0th.

will return a number between 1 & 3, as you have 3 objects. This would work with any number of objects, for example if the array had 6 objects, repeating the same line of code would return a number between 1 & 6.

So now you have the position of the randomly selected object in the array, in order to retrieve the object from the array you would use

x=names[math.random(1,#names)]

So the final code would be,

local amy = script.Amy.BillboardGui
local sarah = script.Sarah.BillboardGui
local joey = script.Joey.BillboardGui
local names = {joey, sarah, amy}

game.Players.PlayerAdded:connect(function(plr)
	x=names[math.random(1,#names)]
	x.Parent = plr.Character:findFirstChild("Head")
end)

3 comments

0

It replies with 'An error occurred' when used like this, I know your answer is correct but It seems not to work.

0

Ah right, I didn't spot that. You can't rename the player. I've modified the code so try it now.

0

What are you trying to do exactly? Remove the players name appearing with the ROBLOX ui? If so just go to StarterPlayer > NameDisplayDistance and set it to 0!

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