|
| 25 Mar 2015 03:36 AM |
local stageStore = game:GetService("DataStoreService"):GetDataStore("StageStore")
game.Players.PlayerAdded:connect(function(player) local stats = Instance.new("IntValue", player) stats.Name = "leaderstats" local stage = Instance.new("IntValue", stats) stage.Name = "Stage" if stageStore:GetAsync("Stage_"..player.Name) ~= nil then stats.Value = stageStore:GetAsync("Stage_"..player.Name) else stage.Value = 0 end stage.Changed:connect(function(newStage) stageStore:SetAsync("Stage_"..player.Name, newStage) end) end)
and I created a button GUI that gives them 10 points..
local player = game.Players.LocalPlayer script.Parent.MouseButton1Down:connect(function() script.Parent.Parent.Parent.Parent.leaderstats.Stage.Value = 10 end)
For some reason it does not save when the player leaves |
|
|
| Report Abuse |
|
|
|
| 25 Mar 2015 04:05 AM |
Uh. You don't have anything that MAKES it store when the player leaves :/
game.Players.PlayerRemoving:connect(function(player) stageStore:SetAsync("whaterver_"..player.Name) end) |
|
|
| Report Abuse |
|
|
|
| 25 Mar 2015 04:09 AM |
Does this not store it?
stage.Changed:connect(function(newStage) stageStore:SetAsync("Stage_"..player.Name, newStage) end) end) |
|
|
| Report Abuse |
|
|
|
| 25 Mar 2015 04:13 AM |
"For some reason it does not save when the player leaves" So, it doesn't store when a player leaves
"Does this not store it?" No, not when the player leaves. Unless you make a change to stage when the player leaves.
|
|
|
| Report Abuse |
|
|
IoIiderp
|
  |
| Joined: 05 Feb 2012 |
| Total Posts: 8613 |
|
|
| 25 Mar 2015 05:47 AM |
It will save even though there are limits. If the username is to long the script will break. Use player.userId instead of player.Name to fix this.
If it changed it will save, this means if it changes to many times and it goes over the limit the script will break.
To stop this you will have to save it when the player leaves. game.Players.PlayerRemoving:connect(function(player) stageStore:SetAsync("Stage_"..player.Name, stage.Value) end)
Next thing, .Changed event returns an Enum what changed. Lets just say it will constantly save "Value" instead of the actual value wich will be for example 20. If the name changed it will return "Name". So use stats.Value. |
|
|
| Report Abuse |
|
|
|
| 25 Mar 2015 06:37 AM |
if stageStore:GetAsync("Stage_"..player.Name) ~= nil then stats.Value = stageStore:GetAsync("Stage_"..player.userId) else stage.Value = 0 end game.Players.PlayerRemoving:connect(function(player) stageStore:SetAsync("Stage_"..player.userId, stage.Value) end)
end)
It does not save, still. |
|
|
| Report Abuse |
|
|
|
| 25 Mar 2015 06:40 AM |
| @cards yeah i cant get it to save i tried that |
|
|
| Report Abuse |
|
|
|
| 25 Mar 2015 06:43 AM |
local stageStore = game:GetService("DataStoreService"):GetDataStore("StageStore")
game.Players.PlayerAdded:connect(function(player) local stats = Instance.new("IntValue", player) stats.Name = "leaderstats" stage = Instance.new("IntValue", stats) stage.Name = "Stage" if stageStore:GetAsync("Stage_"..player.Name) ~= nil then stats.Value = stageStore:GetAsync("Stage_"..player.userId) else stage.Value = 0 end
end)
game.Players.PlayerRemoving:connect(function(player) stageStore:SetAsync("Stage_"..player.userId, player.leaderstats.Stage.Value) end) |
|
|
| Report Abuse |
|
|
|
| 25 Mar 2015 06:44 AM |
if stageStore:GetAsync("Stage_"..player.Name) ~= nil then stats.Value = stageStore:GetAsync("Stage_"..player.userId) else stage.Value = 0 end
Ehm, why are you setting the "stats" value if they have saved before, but the "stage" if they havent? |
|
|
| Report Abuse |
|
|
IoIiderp
|
  |
| Joined: 05 Feb 2012 |
| Total Posts: 8613 |
|
|
| 25 Mar 2015 06:45 AM |
Also put this in the script:
game.OnClose = function() wait(5) end
That will make the server last for 5 seconds longer, wich will give DataStore the time to save the data for the last player. |
|
|
| Report Abuse |
|
|
|
| 25 Mar 2015 06:50 AM |
stageStore = game:GetService("DataStoreService"):GetDataStore("StageStore")
game.Players.PlayerAdded:connect(function(player) local stats = Instance.new("IntValue", player) stats.Name = "leaderstats" stage = Instance.new("IntValue", stats) stage.Name = "Stage" if stageStore:GetAsync("Stage_"..player.Name) ~= nil then stage.Value = stageStore:GetAsync("Stage_"..player.userId) else stage.Value = 0 end
end)
game.Players.PlayerRemoving:connect(function(player) game.OnClose = function() wait(5) end stageStore:SetAsync("Stage_"..player.userId, stage.Value) end)
- Workspace.Leaderboard:20: attempt to index global 'stageStore' (a nil value)
it saids stageStore is a nil value
|
|
|
| Report Abuse |
|
|
|
| 25 Mar 2015 06:52 AM |
for this line: stageStore:SetAsync("Stage_"..player.userId, stage.Value) |
|
|
| Report Abuse |
|
|
|
| 25 Mar 2015 07:04 AM |
stageStore = game:GetService("DataStoreService"):GetDataStore("StageStore")
stageStore apparently doesnt exist.
Are you running this in studio? If so, is the Studio API Access enabled? |
|
|
| Report Abuse |
|
|
|
| 25 Mar 2015 07:23 AM |
stageStore = game:GetService("DataStoreService"):GetDataStore("StageStore") -- Get/Make the Datastore
game.Players.PlayerAdded:connect(function(player) -- Player Added local stats = Instance.new("IntValue", player) -- Creating Value called 'stats' stats.Name = "leaderstats" -- Naming the Value 'leaderstats' stage = Instance.new("IntValue", stats) -- Creating Value called 'stage' stage.Name = "Stage" -- Naming the Value 'Stage' if stageStore:GetAsync("Stage_"..player.Name) ~= nil then -- If player's datastore is true then stage.Value = stageStore:GetAsync("Stage_"..player.userId) -- Set points to stored value else -- or.. stage.Value = 0 -- Set it to zero. end -- end the If end) -- end the PlayerAdded function
game.Players.PlayerRemoving:connect(function(player) -- If player leaves stageStore:SetAsync("Stage_"..player.userId, stage.Value) -- Save the current value of Stage game.OnClose = function() wait(5) end -- hold the server for 5 seconds to allow saving end) -- end the PlayerRemoving function
Thank you I got it! Can you confirm that the my explanations for these lines are correct? |
|
|
| Report Abuse |
|
|
IoIiderp
|
  |
| Joined: 05 Feb 2012 |
| Total Posts: 8613 |
|
|
| 25 Mar 2015 09:38 AM |
game.Players.PlayerRemoving:connect(function(player) -- If player leaves stageStore:SetAsync("Stage_"..player.userId, stage.Value) -- Save the current value of Stage end) -- end the PlayerRemoving function
game.OnClose = function() wait(5) end -- hold the server for 5 seconds to allow saving
Its another event, put it all the way at the bottom. |
|
|
| Report Abuse |
|
|