I'm trying to get my cash and then the daily rewards to save as it should do but i'm getting an error on the server. ServerScriptService.SaveData:11: '=' expected near 'end'

Here are the scripts im using. First is my SaveData script

-- How to save data

local DataStoreService = game:GetService("DataStoreService")

local myDataStore = DataStoreService:GetDataStore("myDataStore")

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local cash = Instance.new("IntValue")
	cash.Name = "Cash"
	cash.Parent = leaderstats
	
	local data
	local success, errormessage = pcall(function()	
		data = myDataStore:GetAsync(player.UserId.."-cash")
	end)
	
	if success then
		cash.Value = DataStoreService
	else
		print("there was an error getting data")
		warn(errormessage)
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	
	local success, errormessage = pcall(funtion()
		myDataStore:SetAsync(player.UserId.."-cash",player.leaderstats.Cash.Value)
end)

	if success then
		print("Data Saved")
	else
		print("Error saving data")
		warn(errormessage)
	end
	
end)

Then its my Currency Riser

amount = 10 -- the amount of cash given
timedelay = 600 -- This is seconds inbetween cash is given
currencyname = "Cash"

while true do
	wait(timedelay)
	for i,v in pairs(game.Players:GetPlayers()) do
		if v:FindFirstChild("leaderstats") and v then
			v.leaderstats[currencyname].Value = v.leaderstats[currencyname].Value + amount
		end
	end
end

Finally its my Rewards script.

local DataStore = game:GetService("DataStoreService"):GetDataStore("DailyRewards")
local hourWait = 24
local possibleRewards = {10,10,10,10,10,5,5,5,5,5,5,5,5,5,5,10,10,10,10,10,10,10,10,10,10,15,15,15,15,15,15,15,15,15,15,20,20,20,20,20,20,20,100,100,100,100,500,500,1000,10000}

game.Players.PlayerAdded:connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
		
	local cash = Instance.new("IntValue")
	cash.Name = "Cash"
	cash.Parent = leaderstats
		
	local timeNow = os.time()
	
	local data
	
	pcall (function()
		data = DataStore:GetAsync(player.UserId.."-dailyRewards") -- players id get function
			print("Getting Data")
	end)
	if data ~= nil then
		local timeSinceLastClaim = timeNow - data
		print("Last Claim"..timeSinceLastClaim)
		if (timeSinceLastClaim / 3600) >= hourWait then
			local reward = possibleRewards[math.random(1,#possibleRewards)]
			game.ReplicatedStorage.ShowDailyReward:FireClient(player,hourWait,reward)
			local connection 
			connection = game.ReplicatedStorage.ClaimReward.OnServerEvent:Connect(function(triggeringPlayer)
				if triggeringPlayer == player then
					print("Reward Claimed")
						player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + reward
						DataStore:SetAsync(player.UserId.."-dailyReward",os.time())
						connection:Disconnect()
				end
			end)
		else
			print("Player cant get this yet")
		end
	else
		print{"New Player"}
		local reward = possibleRewards[math.random(1,#possibleRewards)]
		game.ReplicatedStorage.ShowDailyReward:FireClient(player,hourWait,reward)
		local connection 
		connection = game.ReplicatedStorage.ClaimReward.OnServerEvent:Connect(function(triggeringPlayer)
			if triggeringPlayer == player then
				print("Reward Claimed")
				player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + reward
				DataStore:SetAsync(player.UserId.."-dailyReward",os.time())
				connection:Disconnect()
			end
		end)
	end	
end)
--[[	game.Players.PlayerRemoving:Connect(function(player)
	local data
	pcall(function()
		data = DataStore:GetAsync(player.UserId.."-dailyReward")
		print("Getting the Data Boss")
	end)
if data == nil then
		pcall (function()
			local timeVal = os.time()
			DataStore:SetAsync(player.UserId.."-dailyReward")
		end)
		print("Saved because your new")
	end
end)--]]

Any help would be great. I'm struggling with this.

3 comments

0

Any errors?

0

none

0

"but i'm getting an error on the server. ServerScriptService.SaveData:11: '=' expected near 'end'" - Post description