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)