You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
Hide the button when Rewards claim and show it again after the player can claim the reward again. -
What is the issue? Include screenshots / videos if possible!
when the player click the claim reward, it hides the button ,
but when the player leaves and rejoins the game, the button is visible again to that player even though he already claimed the reward for that day, though there is no reward given since it only gives rewards every 24hrs.
below is the structure of my script .
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
The only solution I tried is the hide button, but as stated above it only hides when players don’t leave the game, but if he leaves and rejoins the button shows again.
Mainscript
local datastoer = game:GetService("DataStoreService")
local daysstroe = datastoer:GetDataStore("DaysStorage103")
local config = require(script.Parent:WaitForChild("MainConfig"))
game.Players.PlayerAdded:Connect(function(player)
local daysfolder = Instance.new("Folder", player)
daysfolder.Name = "Days"
local days = daysstroe:GetAsync(player.UserId)
local clone = script.Script:Clone()
if days then
for i, v in pairs(days) do
local new = Instance.new("BoolValue")
new.Name = i
new.Parent = daysfolder
end
end
clone.Parent = script
clone.Name = player.Name
clone.Disabled = false
end)
function savestats(player)
local days = {}
for i, v in pairs(player.Days:GetChildren()) do
table.insert(days, v.Name)
end
daysstroe:SetAsync(player.UserId, days)
end
game.Players.PlayerRemoving:Connect(function(player)
savestats(player)
end)
game:BindToClose(function()
for i, player in pairs(game.Players:GetPlayers()) do
savestats(player)
end
end)
Script under the mainscript
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local TimeStore = DataStoreService:GetDataStore("TimeStorage103")
local Config = require(script.Parent.Parent.MainConfig)
local CanSave = true
local DNew = false
local labelGui = game.StarterGui.DailyReward.Normal.Cashout
local labelCooldown = 86400
game.ReplicatedStorage.GiveMoney.OnServerEvent:Connect(function(player, plrName)
print("event Fired")
print("Player:", player)
print("Player Name:", plrName)
if player and DNew == false then
DNew = true
end
end)
print("Server script is running")
while true do
wait()
local player = Players:FindFirstChild(script.Name)
if player then
local timeLast = TimeStore:GetAsync(player.UserId)
local currentTime = os.time()
if not timeLast or (currentTime - timeLast) >= 86400 then
local daysFolder = player:FindFirstChild("Days")
local max = 0
for _, v in ipairs(daysFolder:GetChildren()) do
local now = tonumber(v.Name)
if now > max then
max = now
end
end
local nextNum = max + 1
if nextNum - 1 == Config.Days then
daysFolder:ClearAllChildren()
nextNum = 1
end
local reward = Config.checkreward(nextNum, player)
print("Reward:", reward)
DNew = false
repeat
wait()
until DNew == true
local stats = player:FindFirstChild("stats")
if stats then
local currency = stats:FindFirstChild("Currency")
if currency then
currency.Value = currency.Value + reward
print("Rewards have been given")
else
print("Currency value not found in stats")
end
else
print("stats not found")
end
local bool = Instance.new("BoolValue")
bool.Name = tostring(nextNum)
bool.Parent = daysFolder
TimeStore:SetAsync(player.UserId, currentTime)
labelGui.Visible = false
wait(labelCooldown)
labelGui.Visible = true
end
end
end
client side
local player = game.Players.LocalPlayer
local gui = script.Parent
local function claimButtonClicked()
print("Claim button has been clicked!")
local plrName = player.Name
local giveMoneyEvent = game.ReplicatedStorage.GiveMoney
if giveMoneyEvent then
print("Attempting to fire event")
print("Player:", player)
print("Player Name:", plrName)
giveMoneyEvent:FireServer(player, plrName)
print("Event fired to server")
else
print("GiveMoney event not found")
end
end
gui.Activated:Connect(claimButtonClicked)