Chance of something spawning when joining the game

Hello!
I want to make it so when you join the game, there is a random chance of something spawning that wasnt here normally.
For example: there is a 5% chance that when you join the game, car will spawn. If you didnt get lucky, car is not here. I want it to be server sided so car is here for everyone if the server that you are in is lucky.
I dont have any scripts cause i dont know how random works.

2 Likes
math.randomseed(tick())
game.Players.PlayerAdded:Connect(function()
 luck = math.random(1,20)
if luck == 1 then
   --do your stuff

end
end)

oh yes but u forgot about the playeradded part
Edit2: Oh well he afk

1 Like

Try this,

local random = math.random(1,100)
if random <= 5 then
-- spawn car
else
-- unlucky
end

Edit: We both answered at the same time XD @hestolemyrice
Edit2: I didn’t put it because he might want it only once, it is up to him how and where he wants to use

2 Likes

yay it worked thanks! i didnt try script by hestolemyrice, but still thanks

1 Like