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 » Club Houses » Let's Make a Deal
Home Search
 

Re: Whats wrong with this DataStore script?

Previous Thread :: Next Thread 
Jaitix is not online. Jaitix
Joined: 03 May 2014
Total Posts: 17724
23 Aug 2016 06:21 PM
Not going to scripters forum because they are rude.

Anyways, can't figure out what's wrong with this script.

local DataStore = game:GetService("DataStoreService")
local ds1 = DataStore:GetDataStore("PointsDataStore")

game.Players.PlayerAdded:connect(function(player)
local stats = Instance.new("IntValue", player)
stats.Name = "leaderstats"

local Points = Instance.new("IntValue", stats)
Points.Name = "Points"
Points.Value = ds1:GetAsync(player.UserId) or 500
ds1:SetAsync(player.UserId, Points.Value)


Points.Changed:connect(function()
ds1:SetAsync(player.UserId, Points.Value)

game.Players.PlayerRemoving:connect(function(player)
ds1:SetAsync(player.UserId, player.leaderstats.Points.Value)
Points.Value = ds1:GetAsync(player.UserId)
end)


end)

end)

-- if you could help, that'd be great! Thanks!
Report Abuse
L2000 is not online. L2000
Joined: 03 Apr 2008
Total Posts: 77448
23 Aug 2016 06:22 PM
Its better in Scripters because they actually script
LMaDers don't script o3o!!!


If you're seeing this post, it means I'm either dead (leaving behind a very fabulous looking corpse) or my soul has been captured by pixies!
Report Abuse
Widths is not online. Widths
Joined: 12 Aug 2014
Total Posts: 41286
23 Aug 2016 06:22 PM
Maybe people are being rude because you don't understand what's wrong with the script?


-iJava
Report Abuse
Widths is not online. Widths
Joined: 12 Aug 2014
Total Posts: 41286
23 Aug 2016 06:22 PM
because you don't explain what's wrong with the script*********


-iJava
Report Abuse
Jaitix is not online. Jaitix
Joined: 03 May 2014
Total Posts: 17724
23 Aug 2016 06:23 PM
Just realized I had to say what was wrong xD

When I spend some points and leave, and rejoin my points are 500 again. So it never really saves.
Report Abuse
brados1234 is not online. brados1234
Joined: 10 Apr 2013
Total Posts: 3433
23 Aug 2016 06:23 PM
@widths u were waiting for that flame reply xdd


Report Abuse
Widths is not online. Widths
Joined: 12 Aug 2014
Total Posts: 41286
23 Aug 2016 06:25 PM
but anyway there are several issues with the script
first of all, you're creating a bunch of events over and over again each time the points value changes. second of all, Points is gonna be out of scope

fixing it, sec


-iJava
Report Abuse
Jaitix is not online. Jaitix
Joined: 03 May 2014
Total Posts: 17724
23 Aug 2016 06:25 PM
I used to be kind of flamey.

I'm done arguing, time to be someone nice on the internet.
Report Abuse
Blizzardic is not online. Blizzardic
Joined: 07 Aug 2016
Total Posts: 1249
23 Aug 2016 06:25 PM
for starters why are you saving the data whenever the value changes? can I get my overflow in blue pls?

smarter thing to do would be to ONLY save when the player leaves the game

secondly idk what you want to make work and what it's not making work but why is "leaderstats" an intvalue instead of a model?

thirdly why are you using getasync when they leave as if that actually matters? they're gone


Report Abuse
Jaitix is not online. Jaitix
Joined: 03 May 2014
Total Posts: 17724
23 Aug 2016 06:26 PM
@widths


Okay, thanks.


I looked this up on a tutorial, ofc it wasnt copy and paste, I had to edit quite a bit, took me a good hour.
Report Abuse
Widths is not online. Widths
Joined: 12 Aug 2014
Total Posts: 41286
23 Aug 2016 06:26 PM
local DataStore = game:GetService("DataStoreService")
local ds1 = DataStore:GetDataStore("PointsDataStore")

game.Players.PlayerAdded:connect(function(player)
local stats = Instance.new("IntValue", player)
stats.Name = "leaderstats"
local Points = Instance.new("IntValue", stats)
Points.Name = "Points"
Points.Value = ds1:GetAsync(player.UserId) or 500
ds1:SetAsync(player.UserId, Points.Value)
Points.Changed:connect(function()
ds1:SetAsync(player.UserId, Points.Value)
end)
end)
game.Players.PlayerRemoving:connect(function(player)
local stats = player:FindFirstChild("leaderstats")
if stats ~= nil then
Points = Points:FindFirstChild("Points")
if Points ~= nil then
ds1:SetAsync(player.UserId, player.leaderstats.Points.Value)
Points.Value = ds1:GetAsync(player.UserId)
end
end
end)


-iJava
Report Abuse
Jaitix is not online. Jaitix
Joined: 03 May 2014
Total Posts: 17724
23 Aug 2016 06:29 PM
leaderstats is my leaderboard.


Along with points being a child.

Also, I haven't done this before, I thought getting the Async before they left would update the datastore.

Also, it updates every second that way it's always the most updated.
Report Abuse
Blizzardic is not online. Blizzardic
Joined: 07 Aug 2016
Total Posts: 1249
23 Aug 2016 06:30 PM
"Also, it updates every second that way it's always the most updated."

yeah ur gonna overflow in no time if u update every second


Report Abuse
Widths is not online. Widths
Joined: 12 Aug 2014
Total Posts: 41286
23 Aug 2016 06:31 PM
You're allowed 60 + (10*game.Players.NumPlayers) requests to DataStore:SetAsync (and the same amount but on a separate counter to GetAsync) per minute




-iJava
Report Abuse
Jaitix is not online. Jaitix
Joined: 03 May 2014
Total Posts: 17724
23 Aug 2016 06:41 PM
Your code is having some "unknown global" problems with you defining points at the bottom of the code.
Report Abuse
Widths is not online. Widths
Joined: 12 Aug 2014
Total Posts: 41286
23 Aug 2016 06:42 PM
Oops, change the line where I declare Points for the first time to local Points

I had that issue because I initially didn't have local stats and was just changing the value of Points but yeah just add "local" first


-iJava
Report Abuse
Widths is not online. Widths
Joined: 12 Aug 2014
Total Posts: 41286
23 Aug 2016 06:43 PM
local DataStore = game:GetService("DataStoreService")
local ds1 = DataStore:GetDataStore("PointsDataStore")

game.Players.PlayerAdded:connect(function(player)
local stats = Instance.new("IntValue", player)
stats.Name = "leaderstats"
local Points = Instance.new("IntValue", stats)
Points.Name = "Points"
Points.Value = ds1:GetAsync(player.UserId) or 500
ds1:SetAsync(player.UserId, Points.Value)
Points.Changed:connect(function()
ds1:SetAsync(player.UserId, Points.Value)
end)
end)
game.Players.PlayerRemoving:connect(function(player)
local stats = player:FindFirstChild("leaderstats")
if stats ~= nil then
local Points = Points:FindFirstChild("Points")
if Points ~= nil then
ds1:SetAsync(player.UserId, player.leaderstats.Points.Value)
Points.Value = ds1:GetAsync(player.UserId)
end
end
end)



-iJava
Report Abuse
Neximation is not online. Neximation
Joined: 10 May 2014
Total Posts: 12366
23 Aug 2016 06:43 PM
Um


Report Abuse
Widths is not online. Widths
Joined: 12 Aug 2014
Total Posts: 41286
23 Aug 2016 06:44 PM
omg I still didn't fix it RIP

local DataStore = game:GetService("DataStoreService")
local ds1 = DataStore:GetDataStore("PointsDataStore")

game.Players.PlayerAdded:connect(function(player)
local stats = Instance.new("IntValue", player)
stats.Name = "leaderstats"
local Points = Instance.new("IntValue", stats)
Points.Name = "Points"
Points.Value = ds1:GetAsync(player.UserId) or 500
ds1:SetAsync(player.UserId, Points.Value)
Points.Changed:connect(function()
ds1:SetAsync(player.UserId, Points.Value)
end)
end)
game.Players.PlayerRemoving:connect(function(player)
local stats = player:FindFirstChild("leaderstats")
if stats ~= nil then
Points = stats:FindFirstChild("Points")
if Points ~= nil then
ds1:SetAsync(player.UserId, player.leaderstats.Points.Value)
Points.Value = ds1:GetAsync(player.UserId)
end
end
end)








that should work ^


for reference, this was the code i had originally but i changed it a bit for clarity, but when i changed it i didn't change it properly lol



local DataStore = game:GetService("DataStoreService")
local ds1 = DataStore:GetDataStore("PointsDataStore")

game.Players.PlayerAdded:connect(function(player)
local stats = Instance.new("IntValue", player)
stats.Name = "leaderstats"
local Points = Instance.new("IntValue", stats)
Points.Name = "Points"
Points.Value = ds1:GetAsync(player.UserId) or 500
ds1:SetAsync(player.UserId, Points.Value)
Points.Changed:connect(function()
ds1:SetAsync(player.UserId, Points.Value)
end)
end)
game.Players.PlayerRemoving:connect(function(player)
local Points = player:FindFirstChild("leaderstats")
if Points ~= nil then
Points = Points:FindFirstChild("Points")
if Points ~= nil then
ds1:SetAsync(player.UserId, player.leaderstats.Points.Value)
Points.Value = ds1:GetAsync(player.UserId)
end
end
end)




-iJava
Report Abuse
Destr0i is not online. Destr0i
Joined: 29 Apr 2014
Total Posts: 12853
23 Aug 2016 06:46 PM
hackers


Trade: https://www.roblox.com/Trade/TradeWindow.aspx?TradePartnerID=60115810
Report Abuse
XPlaceX is not online. XPlaceX
Joined: 15 May 2014
Total Posts: 7688
23 Aug 2016 06:47 PM
Ur noob af

local DataStore = game:GetService("DataStoreService")
local ds1 = DataStore:GetDataStore("PointsDataStore")

game.Players.PlayerAdded:connect(function(player)
local stats = Instance.new("IntValue", player)
stats.Name = "leaderstats"
local Points = Instance.new("IntValue", stats)
Points.Name = "Points"
Points.Value = ds1:GetAsync(player.UserId) or 500
ds1:SetAsync(player.UserId, Points.Value)
Points.Changed:connect(function()
ds1:SetAsync(player.UserId, Points.Value)
end)
end)
game.Players.PlayerRemoving:connect(function(player)
local stats = player:FindFirstChild("leaderstats")
if stats ~= nil then
Points = stats:FindFirstChild("Points")
if Points ~= nil then
ds1:SetAsync(player.UserId, player.leaderstats.Points.Value)
Points.Value = ds1:GetAsync(player.UserId)
end
end
end)
Report Abuse
Widths is not online. Widths
Joined: 12 Aug 2014
Total Posts: 41286
23 Aug 2016 06:48 PM
um literally all you did was copy and paste my code
what


-iJava
Report Abuse
polfy99 is not online. polfy99
Joined: 06 Nov 2009
Total Posts: 60270
23 Aug 2016 06:49 PM
u stord the datta rong


Report Abuse
XPlaceX is not online. XPlaceX
Joined: 15 May 2014
Total Posts: 7688
23 Aug 2016 06:49 PM
Ya urs seems good
Report Abuse
Widths is not online. Widths
Joined: 12 Aug 2014
Total Posts: 41286
23 Aug 2016 06:49 PM
OMG triggered once again i unfixed another issue when i copy and pasted the wrong code


local DataStore = game:GetService("DataStoreService")
local ds1 = DataStore:GetDataStore("PointsDataStore")

game.Players.PlayerAdded:connect(function(player)
local stats = Instance.new("IntValue", player)
stats.Name = "leaderstats"
local Points = Instance.new("IntValue", stats)
Points.Name = "Points"
Points.Value = ds1:GetAsync(player.UserId) or 500
ds1:SetAsync(player.UserId, Points.Value)
Points.Changed:connect(function()
ds1:SetAsync(player.UserId, Points.Value)
end)
end)
game.Players.PlayerRemoving:connect(function(player)
local stats = player:FindFirstChild("leaderstats")
if stats ~= nil then
local Points = stats:FindFirstChild("Points") --ffs forgot to add the local back
if Points ~= nil then
ds1:SetAsync(player.UserId, player.leaderstats.Points.Value)
Points.Value = ds1:GetAsync(player.UserId)
end
end
end)


-iJava
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Club Houses » Let's Make a Deal
   
 
   
  • 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