Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

I Made this save script and im getting this error help?

game.Players.PlayerAdded:connect(function(player)
	local PlayerStorege = player:WaitForChild("PlayerStorege")
	local RemoteSAVE = PlayerStorege:WaitForChild("RemoteSAVE")
	local RemoteLOAD = PlayerStorege:WaitForChild("RemoteLOAD")
	local Cash = player.PlayerStats:WaitForChild("Cash")

	wait(5)
	Cash.Value = PlayerCashDataStore:GetAsync(player.UserId) or 0
	if PlayerCashDataStore:GetAsync(player.UserId) == 0 then
	Cash.Value = 100
	PlayerCashDataStore:SetAsync(player.UserId, Cash.Value)
			else
	end

ERROR Unable to cast value to function

1 comment

0

If you posted the full code that would help alot, and the error explains itself

1 answer

local DataStore = game:GetService("DataStoreService")
local PlayerCashDataStore = DataStore:GetDataStore("PlayerCashDataStoreeee")



game.Players.PlayerAdded:connect(function(player)
	local PlayerStorege = player:WaitForChild("PlayerStorege")
	local RemoteSAVE = PlayerStorege:WaitForChild("RemoteSAVE")
	local RemoteLOAD = PlayerStorege:WaitForChild("RemoteLOAD")
	local Cash = player.PlayerStats:WaitForChild("Cash")

	wait(5)
	Cash.Value = PlayerCashDataStore:GetAsync(player.UserId) or 0
	if PlayerCashDataStore:GetAsync(player.UserId) == 0 then
	Cash.Value = 100
	PlayerCashDataStore:SetAsync(player.UserId, Cash.Value)
			else
	end
	
	RemoteSAVE.OnServerEvent:connect(function(player)
	
	print("Saving Data for player " .. player.Name .. " of "..Cash.Value)	
	PlayerCashDataStore:UpdateAsync(player.UserId, Cash.Value)
	end)
	
	
	RemoteLOAD.OnServerEvent:connect(function(player)	
	Cash.Value = PlayerCashDataStore:GetAsync(player.UserId)
	end)	
	RemoteLOAD.OnServerEvent:connect(function(player)
	wait(1)
	local PlayerGui = player:WaitForChild("PlayerGui")
	local CashDisplay = PlayerGui:WaitForChild("CashDisplay")
	local CashFrame = CashDisplay:WaitForChild("CashFrame")
	local CashGui = CashFrame:WaitForChild("Cash")
	CashGui.Text = "$".. Cash.Value	
	end)
end)



This discussion is preserved as it was. New answers, comments, and votes are closed.