#More than max coins are spawning
1 messages · Page 1 of 1 (latest)
function CoinSpawner:Spawn()
task.spawn(function()
while true do
local character = self.player.Character or self.player.CharacterAdded:Wait()
local root = character:WaitForChild("HumanoidRootPart")
if CurrentCoins > MaxCoins then return end
if CurrentCoins <= MaxCoins then
CurrentCoins += 1
local coin = Instance.new("Part")
coin.Size = Vector3.new(1, 1, 1)
coin.Shape = Enum.PartType.Ball
coin.Anchored = false
coin.CanCollide = false
coin.Name = "Coin"
coin.BrickColor = BrickColor.Random()
coin.Parent = workspace:WaitForChild("Coins")
local offset = Vector3.new(math.random(-50, 50), 2, math.random(-50, 50))
coin.Position = root.Position + offset
FollowPlayer(coin, root)
coin.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
CurrentCoins -= 1
coin.CanTouch = false
coin:Destroy()
GiveCoinEvent:FireServer()
end
end)
end
task.wait(1)
end
end)
end
If CurrentCoins > MaxCoins then
break
that would stop the while true do
if currentcoins <= maxcoins… meaning if current coins is 3, and max is 4 then itll create a coin making it 4/4 but since ur doing less than or equal too, its gonna spawn an extra cause 4 = 4 so itll be 5/4