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

My billboard gui script is not working..?

Asked by
IcyEvil 260 Moderation Voter
8 years ago

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
Please tell us what you want to do. This script right now tells me NOTHING! sigve10 94 — 8y

1 answer

Log in to vote
1
Answered by 8 years ago

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)

0
It replies with 'An error occurred' when used like this, I know your answer is correct but It seems not to work. IcyEvil 260 — 8y
0
Ah right, I didn't spot that. You can't rename the player. I've modified the code so try it now. substratosphere 20 — 8y
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! substratosphere 20 — 8y
Ad

Answer this question