|
| 07 Aug 2017 07:57 PM |
In scripting how would I find out if this is the first time the player has ever joined my game? I want to create a GUI the player will see only the first time they join so they can select a starter weapon. Then the second time the player will not receive the GUI and will have the starter weapon in their inventory. I already know how to save the weapon using datastores but not sure about the GUI. I was thinking of when I check for the datastore I could put in an else command and then have the GUI appear but the weapon can be traded so if the player traded it away the GUI would appear again.
Something I was thinking of was to create a Boolean datastore value that changes to true when the player chooses their weapon so then after they traded it the value is still true, and new players default value would be false. I guess it would work for now but I'd have to find a new way in a later update I plan so I was just wondering if there were a way to check if it's the players first time joining through an event/function. If you know please reply, I'd appreciate the help. |
|
|
| Report Abuse |
|
|
|
| 07 Aug 2017 07:58 PM |
| local stats = ################ if not stats then print'new player' else print 'returning player end |
|
|
| Report Abuse |
|
|
|
| 07 Aug 2017 08:05 PM |
If you are storing data in your game, you could check if the player's userId is in the DataStore, if not insert the userId and give them the GUI.
|
|
|
| Report Abuse |
|
|
|
| 07 Aug 2017 08:07 PM |
| save a boolean called hasPlayed to the player via datastores and re-save it as true once they pick their weapon (not once they join because that might result in them leaving and coming back and not being able to pick their weapon) |
|
|
| Report Abuse |
|
|
RobuxLife
|
  |
| Joined: 19 Sep 2012 |
| Total Posts: 13336 |
|
|
| 07 Aug 2017 09:08 PM |
local dataStoreService = game:GetService("DataStoreService") local hasPlayedDatastore = dataStoreService:GetDataStore("hasPlayedDataStore")
game.Players.PlayerAdded:connect(function(player) local key = "player-" .. player.userId local hasPlayed = Instance.new("BoolValue", player) hasPlayed.Name = "hasPlayed" local savedValues = hasPlayedDatastore:GetAsync(key) if savedValues then hasPlayed.Value = true hasPlayed:Destroy() else hasPlayed.Value = true hasPlayedDatastore:SetAsync(key, hasPlayed.Value) print(key, player.Name .. " is new") end
end)
- RL |
|
|
| Report Abuse |
|
|