Hey,
Thanks to all the supports from all of you from before.
So recently, I am stuck with a simple problem. So if a special player (chosen player) joins the game for the first time, they will receive a special amount of data value (note: NOT leaderstats.)
Data as reference:
Failed tries:
-I tried to make a value under the script that if the special player joined once, it will be always marked true.
-I tried to mark the join as a leaderstat, each time he joins the value adds by 1, and if the value is > 1 the script will not give cash to the special player.
local Players = game:GetService("Players")
local function chooseRandomPlayer(m : number?): Player
local allPlayers = Players:GetPlayers()
return allPlayers[math.random(m,#allPlayers)]
end
Players.PlayerAdded:Connect(function(player)
chooseRandomPlayer(1) -- returns a random player from the game
end)
This just chooses a random player from the game when the player joins. Not sure if this is what you wanted though.
If you mean like first time, then have a datastore that detects if they joined for the first time, if true, then for example do this: if math.random(1, 50) == 50 then. This will give them a 1 in 50 chance of getting the special award.
I think you mean the player will join first time to you game, right?
DataStores will definitely help you with the information is a player has joined before.
If your special player is meant a player with specific ID, them make a simple if statement checking for player’s ID, then call DataStore with name for example "PlayerJoinTimestamp" and search for a value with key specialPlayer.UserId, if result has been found, then the player has joined your game at least once, if there’s no such value, give him your prize and use the datastore once again to store that the player has received its prize, so basically use the same key and insert a value DateTime.now().UnixTimestamp which is datetime in seconds when the player has joined your game for the first time.
Just do a simple if statement and then have the stat get set to a specific value AFTER you get the datastore values, after that, just save the value back to the datastore