So recently I’ve been trying to do something where a script runs when a player is added, but only when the first player is added and after never running again. In less confusing terms a script that runs when a players joins ONCE and never when a 2nd or higher player joins. Could you guys help me?
You could disable the script or check if it is the first player.
local players = 0
game.Players.PlayerAdded:Connect(function(plr)
players = players + 1
if players == 1 then
--run a function
else
--do nothing
end
end)
other script
game.Players.PlayerAdded:Connect(function(plr)
--run a function
script.Parent.Disabled = true
end)
If you want a script to trigger once just have it it run when the server is started. Please tell me if I’m missing something here and not understanding your question fully.
sometimes this doesn’t work but other times it does, im using a math.random in the script and I did everything you said, did I do something wrong? btw I used it in the way the math.random is shown in the original script
If think the issue is your if statement is generating numbers inside of it. Store your first math.random() as a variable and use the variable in your if statements.
local randomNumber = math.random(1,3)
if randomNumber == 3 then
print("3")
end