generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Datastore Problem

Previous Thread :: Next Thread 
DJSasuke1963 is not online. DJSasuke1963
Joined: 30 Nov 2012
Total Posts: 1136
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
distalDigitPhalanx is not online. distalDigitPhalanx
Joined: 25 Jan 2015
Total Posts: 1509
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
DJSasuke1963 is not online. DJSasuke1963
Joined: 30 Nov 2012
Total Posts: 1136
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
distalDigitPhalanx is not online. distalDigitPhalanx
Joined: 25 Jan 2015
Total Posts: 1509
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 is not online. 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
CardsOfFate is not online. CardsOfFate
Joined: 08 Jul 2014
Total Posts: 761
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
DJSasuke1963 is not online. DJSasuke1963
Joined: 30 Nov 2012
Total Posts: 1136
25 Mar 2015 06:40 AM
@cards yeah i cant get it to save i tried that
Report Abuse
DJSasuke1963 is not online. DJSasuke1963
Joined: 30 Nov 2012
Total Posts: 1136
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
epicbreaker is not online. epicbreaker
Joined: 23 Apr 2011
Total Posts: 2791
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 is not online. 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
DJSasuke1963 is not online. DJSasuke1963
Joined: 30 Nov 2012
Total Posts: 1136
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
DJSasuke1963 is not online. DJSasuke1963
Joined: 30 Nov 2012
Total Posts: 1136
25 Mar 2015 06:52 AM
for this line:
stageStore:SetAsync("Stage_"..player.userId, stage.Value)
Report Abuse
epicbreaker is not online. epicbreaker
Joined: 23 Apr 2011
Total Posts: 2791
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
DJSasuke1963 is not online. DJSasuke1963
Joined: 30 Nov 2012
Total Posts: 1136
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 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image