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)
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)