I have a script that saves Money from Players so they keep it the next time they join but it gives an error and I dont know how to fix it. Here is my script:
local DSService = game:GetService('DataStoreService'):GetDataStore('Hamburger223232')
game.Players.PlayerAdded:connect(function(plr)
-- Define variables
print('waiting until tycoonscript ready')
wait(6)
print('Starting')
local uniquekey = 'id-'..plr.userId
local leaderstats = Instance.new('IntValue', plr)
local Moneystorage = game.ServerStorage:FindFirstChild('PlayerMoney')
local PlayerMoney = Moneystorage:FindFirstChild(plr.Name)
local savevalue = PlayerMoney
--leaderstats.Name = 'leaderstats'
--savevalue.Parent = leaderstats
--savevalue.Name = 'Cash'
-- GetAsync
local GetSaved = DSService:GetAsync(uniquekey)
if GetSaved then
savevalue.Value = GetSaved[1]
else
local NumbersForSaving = {savevalue.Value}
DSService:SetAsync(uniquekey, NumbersForSaving)
end
end)
game.Players.PlayerRemoving:connect(function(plr)
local Moneystorage = game.ServerStorage:FindFirstChild('PlayerMoney')
local PlayerMoney = Moneystorage:FindFirstChild(plr.Name)
local savevalue = PlayerMoney
local uniquekey = 'id-'..plr.userId
local Savetable = {savevalue.Value}
DSService:SetAsync(uniquekey, Savetable)
end)
When i test it with an alt in game this is what shows in the output.
ServerScriptService.Save Service :19: attempt to index local 'savevalue' (a number value)
If anybody could help that would be amazing '

1 comment
It works now Thanks for your help.