Log in to vote

Why is a Local Part destroyed or not destroyed depending on a value?

Asked by 4 days ago
Edited 4 days ago

Sorry to ask such a simple question, but I've been scratching my head at this for a while now. I have a script that generates a local part and automatically destroys it when Rebirths, a leaderstats value, is >= 1. Here is the script:

local Player = game.Players.LocalPlayer
local Leaderstats = Player:WaitForChild('leaderstats')
local Rebirths = Leaderstats.Rebirths

local Part ='Part')
Part.Parent = game.Workspace
Part.Size =, 50, 410)
Part.Position =, 0, 0)
Part.Anchored = true
Part.Transparency = 0.5
Part.BrickColor = BrickColor.Red()


if Rebirths.Value >= 1 then


This is the script, and for some reason after I rebirth for the first time (and ''Rebirths'' changes to 1) nothing happens.

Here is the important part: For some reason, when I change the final If statement to >= 0 INSTEAD of >= 1, it works completely fine, printing Milestone and destroying the Local Part. Why is this?

1 answer

Log in to vote
Answered by
HEMAN_9 70
4 days ago

The problem is that your code only checks if it should destroy the part the one time it is first ran. to fix this and get the desired result you could use the event ".Changed" for the rebirth leaderstat. on line 14 you could write: Rebirths.Changed:Connect(function(value)

if value >= 1 then print('Milestone') Part:Destroy() end


this way anytime the value of "Rebirths" changes that function will run and destroy the part if it is greater or equal to 1.

Hope this helps

I honestly have no idea how this flew over my head, but thank you. TheGamerGuy82 8 — 4d

Answer this question