Daily reward script broken

I’m trying to make a daily reward script, but the button does not do anything.
It has given me two errors.
In the first script, on line 7, it says "Players.OoferMcOofman.PlayerGui.DailyReward.LocalScript:7:attempted to concatenate table with string.
Script:

game.ReplicatedStorage.ShowDailyReward.OnClientEvent:Connect(function(hoursToNextReward, rewardAmount)
	script.Parent.Enabled = true
	script.Parent.Frame.Comeback.Text = "Come back in "..hoursToNextReward.." hours for your next reward"
	
	script.Parent.Frame.Claim.MouseButton1Click:Connect(function()
		game.ReplicatedStorage.ClaimReward:FireServer()
		script.Parent.RewardNotice = "You got "..rewardAmount.." Credits!"
		script.Parent.RewardNotice:TweenSizeAndPosition(UDim2.new(0.6,0,0.15,0), UDim2.new(0.5,0,0.5,0))
		script.Parent.Frame.Visible = false
		wait(1.5)
		script.Parent.RewardNotice:TweenSizeAndPosition(UDim2.new(0,0,0,0), UDim2.new(0.5,0,0.5,0))
		wait(1.5)
		script.Parent.Enabled = false
		script.Parent.Frame.Visible = true
	end)
	
end)

The second error says "ServerScriptService.Script:60:attempt to preform arithmetic (add) on number and table.
Script:

local DataStore = game:GetService("DataStoreService"):GetDataStore("DailyRewards")

local hourWait = 24

local possibleRewards = {25}


game.Players.PlayerAdded:Connect(function(player)
	
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local credits = Instance.new("IntValue")
	credits.Name = "Credits"
	credits.Parent = leaderstats
	
	local timeNow = os.time()
	
	local data
	
	pcall(function()
		data = DataStore:GetAsync(player.UserId.."-dailyReward")
		print("Getting data, this is for testing purposes, don't mind this.")
	end)
	
	if data ~= nil then
		
		
		local timeSinceLastClaim = timeNow - data 
		
		print("Testing..testing...Time since last claim"..timeSinceLastClaim)
		
		if (timeSinceLastClaim / 3600) >= hourWait then
			
			local reward = possibleRewards
			game.ReplicatedStorage.ShowDailyReward:FireClient(player, hourWait, reward)
			local connection 
			connection = game.ReplicatedStorage.ClaimReward.OnServerEvent:Connect(function(triggeringPlayer)
				if triggeringPlayer == player then
					print("Test: Reward Claimed")
					player.leaderstats.Credits.Value = player.leaderstats.Credits.Value + reward
					DataStore:SetAsync(player.UserId.."-dailyReward",os.time())
					connection:Disconnect()
				end
			end)
		else
			print("Test:Player cannot get reward at current time.")
		end
			
	else
		print("this is a new player.")
		
		local reward = possibleRewards
		game.ReplicatedStorage.ShowDailyReward:FireClient(player, hourWait, reward)
		local connection 
		connection = game.ReplicatedStorage.ClaimReward.OnServerEvent:Connect(function(triggeringPlayer)
			if triggeringPlayer == player then
				print("Test: Reward Claimed")
				player.leaderstats.Credits.Value = player.leaderstats.Credits.Value + reward
				DataStore:SetAsync(player.UserId.."-dailyReward",os.time())
				connection:Disconnect()
			end
		end)
	end
	
end)

rewardAmount must be a table instead of a value or string. Try printing rewardAmount

Alright…so…just want to say that I’m not the best scripter, so I’m a little confused. Where do I print rewardAmount?

ANywhere before the line where the error occours. That way you can check what value the variable holds and maybe reveal what’s going wrong with your code.

I’d recommend also trying the debugger. Simply set a breakpoint at the start of the function that errors and run the code, it should stop at the breakpoint and you can then step through the code 1 line at a time and inspect all variables.

Alrighty, well, I put it there, and it doesn’t even print. So I’m still a bit confused.

1 Like

Please show us how you did that

game.ReplicatedStorage.ShowDailyReward.OnClientEvent:Connect(function(hoursToNextReward, rewardAmount)
	script.Parent.Enabled = true
	script.Parent.Frame.Comeback.Text = "Come back in "..hoursToNextReward.." hours for your next reward"
	print (rewardAmount)
	
	script.Parent.Frame.Claim.MouseButton1Click:Connect(function()
		game.ReplicatedStorage.ClaimReward:FireServer()
		script.Parent.RewardNotice = "You got "..rewardAmount.." Credits!"
		script.Parent.RewardNotice:TweenSizeAndPosition(UDim2.new(0.6,0,0.15,0), UDim2.new(0.5,0,0.5,0))
		script.Parent.Frame.Visible = false
		wait(1.5)
		script.Parent.RewardNotice:TweenSizeAndPosition(UDim2.new(0,0,0,0), UDim2.new(0.5,0,0.5,0))
		wait(1.5)
		script.Parent.Enabled = false
		script.Parent.Frame.Visible = true
	end)
	
end)

make the possible rewards in the serversript a number instead of a table

local possibleRewards = 25

or make it get the value using something like table.unpack on the client

thatll fix the client script

this will also fix the server script error

Alright, that did get rid of of the errors (thank you)
Oddly, I have a brand new error: RewardNotice is not a valid member of ScreenGui.

I’m afraid I have to say this, but you rather seem to be lazy.

Do you not know how to fix errors? Please give me this information. The root of that error is caused by ‘RewardNotice’ not being a valid child of ‘ScreenGui’.

Alright, I’m going to admit that I can be lazy at times. However, I do try to learn as much as possible, whenever I can.
I looked at the link, and I noted it fit into common error number one.
But I’m still a bit confused.
I see RewardNotice as a child to ScreenGui, so I still don’t really understand.
Am I being dumb?

Update: I figured it out using other resources.