local DataStore = game:GetService(("DataStoreService"):GetDataStore("Daily Rewards") local hourWait = 24 local possibleRewards = {10,15,20,5,5,5,5,5,5,5,5,5,5,5,100,250} game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parents = player local coins = Instance.new ("IntValue") coins.Name = "Coins" coins.Parent = leaderstats local timeNow= os.time() local data pcall (function() data = DataStore:GetAsync(player.UserId.."-dailyReward") print ("Getting Data") end) if data ~= nil then --Returning player to the game local timeSinceLastPlay = timeNow - data -- Number in sec since the last reward was claimed print ("Time since last claim"..timeSinceLastClaim) if (timeSinceLastClaim / 3600) >= hourWait then --They are eligible for a reward 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.leaderstat.Coins.Value = player.leaderstat.Coins.Value + reward DataStore:SetAsync(player.UserId.."-dailyReward",os.time()) connection:Disconnect() end end) else print("Player is uneligible right now") end else --New player print("New player") end end) game.Players.PlayerRemoving:Connect((function(player) local data pcall(function() data = DataStore:GetAsync(player.UserId.."-dailyReward") print ("Getting the Data") end) if data ==nil then -- New player pcall((function() local timeVal = os.time() DataStore.GetAsync(player.UserId.."dailyReward") end) print("Saved because you are a new player") end end) ----------------------- ----------------------- game.ReplicatedStorage.ShowDailyReward.OnClientEvent:Connect(function(hourToNextReward,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.Text = "You got "..rewardsAmount.."Coins" 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)
i dont know where is the problem and i have the remote event in rep storage so please i need a help btw its 2 scripts