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 |
|
|
| |
|
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
|
  |
| 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
|
  |
| 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
|
  |
| Joined: 17 Jun 2013 |
| Total Posts: 23601 |
|
|
| 05 Aug 2017 06:15 PM |
You can't user DataStore in a LocalScript
|
|
|
| Report Abuse |
|
|
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 |
|
|