hello,
i made chest system like the one inside bubble gum simulator but when the system tell to the player wait if he rejoin the chest respawn, what should i do/use so the chest system will no respawn the chest when the player rejoin?
thanks for the help.
If you wanted like a daily chest or similar one, you can store a tick in a datastore when player claims the chest & when player rejoins that time you just check if 24 hours have passed since the stored tick, and depending on that you could spawn the chest.
I can’t really give you the code, as Dev forum isn’t for spoon feeding but you could try to do it yourself or look at previous threads, Or look at these API References / Dev forum threads for information on tick & datastores
is will work with 25 mins or one hour?
Surely it will, you just store the time in the datastore & later you just check if 60 minutes have passed since that time.
Actually instead of tick, you could use os.time, I personally use os.time. Ima write a quick example to show you how you could do it.
When player claims:
local claimTime = os.time() --You get the current time and store it.
chestClaimDatastore:UpdateAsync(claimTime)
When player wants to reclaim / Rejoins
local lastClaimTime = chestClaimDatastore:GetAsync() or os.time()
local currentTime = os.time()
if currentTime - lastClaimTime >= 3600 then --3600 is same as 1 hour but in seconds
--This is where you spawn the chest
end
thanks but is no works…
That was meant to be an example, anyways can you post your full script here?
inside server script service:
local DataStoreService = game:GetService("DataStoreService")
local chestClaimDatastore = DataStoreService:GetDataStore("chestClaimDatastore")
game.Workspace:FindFirstChild("Chest").ChestPad.Touched:Connect(function(hit, player)
local claimTime = os.time() --You get the current time and store it.
chestClaimDatastore:UpdateAsync(player, claimTime)
end)
game.Players.PlayerAdded:Connect(function(player, hit)
local lastClaimTime = chestClaimDatastore:GetAsync(player.UserId) or os.time()
local currentTime = os.time()
if currentTime - lastClaimTime >= 3600 then --3600 is same as 1 hour but in seconds
if game.ServerStorage:FindFirstChild("Chest") then
game.ServerStorage:FindFirstChild("Chest").Parent = game.Workspace
elseif not game.ServerStorage:FindFirstChild("Chest") then
print("Didnt Claimed Chest.")
end
end
end)
inside the chest pad:
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent:FindFirstChild("Humanoid") ~= nil then
script.Parent.Parent.Parent = game.ServerStorage
end
end)
Sorry I was pretty busy with some work, so there are a few problems in your script, which I will fix & then explain you what each line is doing.
local DataStoreService = game:GetService("DataStoreService")
local chestClaimDatastore = DataStoreService:GetDataStore("chestClaimDatastore")
game.Players.PlayerAdded:Connect(function(player)
local lastClaimTime = chestClaimDatastore:GetAsync(player.UserId) or os.time()
local currentTime = os.time()
if currentTime - lastClaimTime >= 3600 then --3600 is same as 1 hour but in seconds
if game.ServerStorage:FindFirstChild("Chest") then
local newChest = game.ServerStorage:FindFirstChild("Chest"):Clone() --You clone the chest & parent it to the Workspace, you can do position etc yourself too
newChest.Parent = game.Workspace
local ChestPadConnection
ChestPadConnection = game.Workspace:FindFirstChild("Chest").ChestPad.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent) --You will need to get the player like this, because player isn't passed as an arguement
if not player then return end --Break the thread if player isn't found with the hit.
ChestPadConnection:Disconnect() --If the hit is a player, then we disconnect the pad .Touched event & also destroy the chest
newChest:Destroy()
--Updating the next claim time, to 1 hour later
local nextClaimAt = os.time() + 3600
chestClaimDatastore:SetAsync(player.UserId, nextClaimAt)
--In Here you can do stuff like giving rewards
--example: player.leaderstats.cash.Value += 1000
end)
end
end
end)
You might also need a client sided loop to check if 1 hour has been past, because if the player stats in game for more than an hour that code won’t work because it works only on PlayerAdded events. Also if you do make a loop, make sure you have server sided checks that actually verify if 1 hour has been past since last claim.
Also you don’t need the script inside of the chest pad actually, this code will do everything, you just need to understand what it does with the comments I left & then continue to modify it according to your needs
Hope this helps you