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

How do i make players in my roblox game spawn with a random item?

Asked by 3 years ago

I would like to make the item different every time that they respawn and each player has a different set of items.

I found this code but it is not working: Item1 = game.Lighting.ItemName Item2 = game.Lighting.ItemName Item3 = game.Lighting.ItemName Items = {Item1, Item2, Item3}

SpawnItem = Items[math.random(#Items, 1)] 
SpawnItem:clone().Parent =

thanks in advance!

2 answers

Log in to vote
1
Answered by 3 years ago

Make sure that this is a server script.

local Items = game.Lighting:GetChildren()

game.Players.PlayerAdded:Connect(function(player)
    local SpawnItem = Items[math.random(1, #Items)]:Clone()
    SpawnItem.Parent = player.Backpack
end)
0
NOOB!!!!!!!!!!!!!!!!!!!!!!!!!!! Vexanonymous 6 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

parent the item to the thing u want it to be in

and replace the item names, you can also always add more stuff u want to spawn.

input whatever items u want to clone

local SpawnItem = math.random(1, 3) 

if SpawnItem == 1 then
Item1:clone()
Item1.Parent =  

elseif SpawnItem == 2 then
Item2:clone()
Item2.Parent = 

elseif SpawnItem == 3 then
Item3:clone()
Item3.Parent = 

end
0
that's not a very good way to randomize the items, if he wanted to add more items it would take of hundreds of lines of code for no reason at all. There's an easier way to do it in about like 3 lines of code. Read my post that I posted. Afraid4Life 5 — 3y

Answer this question