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

I need to make a randomized and rarity spawner but how do you add rarities?

I am trying to make a game, like when you die, you spawn with a different item each time. I want it to have rarities, like common, uncommon, etc... Or like 50%, 25% etc... But unfortunately, I only have this code.



function died(deadplayer)

end

game.Players.ChildAdded:connect(function(newPlayer)
	
newPlayer.CharacterAdded:connect(function(newCharacter)
	local Backpack = newPlayer.Backpack
wait(0.01)
newCharacter.Humanoid.Died:connect(function() died(newCharacter) end)
    game.ReplicatedStorage.Tools.Common.ClassicSword:Clone().Parent = Backpack
end)
end)

There are 5 rarites in the ReplicatedStorage, and This script is in the ServerScriptService.

This script is a Script, not a LocalScript.

I need to make it randomized and also add rarities.

1 answer

✓ Accepted answer

Use math.random() to generate random values. Based on these random values, give different items.

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