Hello.
I have a chest in the game that is quite difficult to get to. how do I make a script that will increase the prize every second until someone gets to the chest? and after touching it, the prize is reset to 0 and starts to grow again until someone takes it away.
Your request is very basic. I’d suggest looking into some scripting tutorials and playing with lua code a bit. The dev forums can help you with complicated problems, but isn’t really here to walk you through your learning process.
…
local chest = workspace.Chest
local prize = 0
function openChest(player)
print('Award', player, prize)
prize = 0
end
chest.Touched:connect(function(hit)
if hit and hit.Parent then
local player = game:GetService('Players'):GetPlayerFromCharacter(hit.Parent)
if player then
openChest(player)
end
end
end)
while true do
wait(1)
prize = prize + 1
end
1 Like
local chest = script.Parent --assuming the chest is a single part or the prize awarding is done from a single part of some chest model
local debounce = false
local prize = 0
chest.Touched:Connect(function(hit)
if debounce then --debounce adds a cooldown
return
end
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
debounce = true
player.leaderstats.Coins.Value += prize
prize = 0
hit.Parent:BreakJoints() --kills the player so they cant claim the prize again
end
task.wait(10) --cooldown before prize can be claimed again
debounce = false
end)
while task.wait(1) do
prize += 1
end
If you have a leaderstats with a stat named “Coins” this will increase the value of coins by the current prize. Feel free to swap the stat “Coins” for a different stat name if the stat uses a different name.