I'm making a random chest spawning spot but there's a problem. Here's the code:
local treasure = script.Parent.Treasure.Value local common = game.Lighting.Chests.CommonChest1 local uncommon = game.Lighting.Chests.UncommonChest1 local rare = game.Lighting.Chests.RareChest1 local epic = game.Lighting.Chests.EpicChest1 local legendary = game.Lighting.Chests.LegendaryChest1 local chances = {common,common,common,common,common,common,common,common,common,common,uncommon,uncommon,uncommon,uncommon,uncommon,rare,rare,rare,epic,epic,legendary} while wait(10) do if treasure == false then treasure = true chest = chances[math.random(1,#chances)]:Clone() chest.Parent = script.Parent end end
When the player takes the chest the treasure value is set back to false so that's not a problem, but still it doesn't spawn another chest. Can anybody help please?
You've set the treasure variable to true but forgot to change it back to false so it can run what's in the if statement again.
The chest's code:
local box = script.Parent.HitBox local coinsreward = script.Parent.Configuration.CoinsReward.Value local expreward = script.Parent.Configuration.ExpReward.Value box.Touched:Connect(function(part) local parent = part.Parent local humanoid = parent:FindFirstChild("Humanoid") local player = game.Players:GetPlayerFromCharacter(parent) if humanoid ~= nil and player then player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + coinsreward player.leaderstats.Exp.Value = player.leaderstats.Exp.Value + expreward script.Parent.Parent.Treasure.Value = false game:GetService("Debris"):AddItem(script.Parent,0) end end)