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: DateSave Help

Previous Thread :: Next Thread 
DecyI is not online. DecyI
Joined: 04 Oct 2015
Total Posts: 20
05 Aug 2017 03:33 PM
Hey, So i have 2 scripts, one as a datasave(Script) and one as a Local script(Button)
But some reason even though it changes the values in game, it doesnt save when you leave. But the thing is when i change the value in Developer thing in game, it does save?
Can anyone help? Here is the script

Data save Script:
local DSService = game:GetService('DataStoreService'):GetDataStore('Values')
game.Players.PlayerAdded:connect(function(plr)

local uniquekey = 'id-'..plr.userId
local leaderstats = Instance.new('IntValue',plr)
local savevalue = Instance.new('IntValue')
local savevalue2 = Instance.new('IntValue')
local savevalue3 = Instance.new('IntValue')

leaderstats.Name = 'leaderstats'

savevalue.Parent = leaderstats
savevalue2.Parent = leaderstats
savevalue3.Parent = leaderstats

savevalue.Name = 'Cash'
savevalue2.Name = 'Value1'
savevalue3.Name = 'Value2'

local GetSaved = DSService:GetAsync(uniquekey)
if GetSaved then
savevalue.Value = GetSaved[1]
savevalue2.Value = GetSaved[2]
savevalue3.Value = GetSaved[3]
else
local NumbersForSaving = {savevalue.value, savevalue2.value, savevalue3.value}
DSService:SetAsync(uniquekey,NumbersForSaving)

end
end)

game.Players.PlayerRemoving:connect(function(plr)
local uniquekey = 'id-'..plr.userId
local Savetable = {plr.leaderstats.Cash.Value, plr.leaderstats.Value1.Value, plr.leaderstats.Value2.Value}
DSService:SetAsync(uniquekey,Savetable)
end)

Local Script:
local plr = game.Players.LocalPlayer
local Cash = plr.leaderstats.Value1
local PlayerCash = plr.leaderstats.Cash

function OnClick()
workspace.Sound:Play()
if PlayerCash.Value > Cash.Value then
PlayerCash.Value = PlayerCash.Value - Cash.Value
plr.leaderstats.Value1.Value = plr.leaderstats.Value1.Value+700
script.Parent.Parent.Visible = false
else
if PlayerCash.Value < Cash.Value then
script.Parent.Parent.TextLabel.Text = 'Insufficient Funds'
wait(4)
script.Parent.Parent.TextLabel.Text = 'Purchase Accessories Crate'
end
end
end

script.Parent.MouseButton1Down:connect(OnClick)




Report Abuse
bellatractive is not online. bellatractive
Joined: 17 Mar 2017
Total Posts: 30
05 Aug 2017 03:39 PM
wow :(
Report Abuse
RealBeta is online. RealBeta
Joined: 23 Jun 2013
Total Posts: 440
05 Aug 2017 03:39 PM
Mostly because the character is being loaded too fast is to why it only works in play solo, try repeating until the character is fully loaded in by using "repeat wait() until player.Character"


#UnleashedDevelopment
Report Abuse
DecyI is not online. DecyI
Joined: 04 Oct 2015
Total Posts: 20
05 Aug 2017 05:21 PM
Ok thank you!, Ill try it now and post back on here with an update


Report Abuse
DecyI is not online. DecyI
Joined: 04 Oct 2015
Total Posts: 20
05 Aug 2017 06:14 PM
I have tried to use repeat wait() until player.character but it still doesnt seem to work, i've been thinking if its because the local script needs to be a script?


Report Abuse
Laedere is online. Laedere
Joined: 17 Jun 2013
Total Posts: 23601
05 Aug 2017 06:15 PM

You can't user DataStore in a LocalScript


Report Abuse
DecyI is not online. DecyI
Joined: 04 Oct 2015
Total Posts: 20
05 Aug 2017 06:51 PM
I used a script for Data store but i have then used a local script, the local script changes the text but it seems like it doesn't actually change the value. I tested in game if it was saving the data but it wasn't..

Heres the local script, I cant tell whats wrong with it?

local plr = game.Players.LocalPlayer
local Cash = plr.leaderstats.Value1
local PlayerCash = plr.leaderstats.Cash

function OnClick()
repeat wait() until plr.Character
workspace.Sound:Play()
if PlayerCash.Value > Cash.Value then
PlayerCash.Value = PlayerCash.Value - Cash.Value
plr.leaderstats.Value1.Value = plr.leaderstats.Value1.Value+700
script.Parent.Parent.Visible = false
else
if PlayerCash.Value < Cash.Value then
script.Parent.Parent.TextLabel.Text = 'Insufficient Funds'
wait(4)
script.Parent.Parent.TextLabel.Text = 'Purchase Accessories Crate'
end
end
end

script.Parent.MouseButton1Down:connect(OnClick)




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