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

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

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

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)

1 comment

0

NOOB!!!!!!!!!!!!!!!!!!!!!!!!!!!

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

1 comment

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.

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