Do Something If IntValue Has Specific Value

Hello!,
I have an IntValue inside ReplicatedStorage for purposes. I wanted to simply destroy (remove) a model inside the workspace and replace another model on that specific position.

local donate = game.ReplicatedStorage.TotalDonation
local total = donate.Value

if total.Value >= 1000000 then -- greater than equal a million?
	local donation = game.Workspace.DonationStation
	donation:Destroy()
	wait()
	local rich = game.ReplicatedStorage.MrRich
	rich.Parent = workspace
end

The problem is, that model isn’t destroying

And the problem is…? Not destroying?

Yep, sorry forgot to add the problem

Your current script runs only once and that is when the game starts.

local donate = game.ReplicatedStorage.TotalDonation
local total = donate.Value

donate:GetPropertyChangedSignal("Value"):Connect(function()
    if total.Value >= 1000000 then -- greater than equal a million?
	  local donation = game.Workspace.DonationStation
	  donation:Destroy()
	  wait()
	  local rich = game.ReplicatedStorage.MrRich
	  rich.Parent = workspace
    end
end)

You need to Check when the Value changes.
The Script only checks once so it wont run further on.

Here i use GetPropertyChangedSignal.
This Detects when the Value changes and Destroys the model.

1 Like

Also you should use debris instead of destroy

1 Like

They are basically almost the same thing.


Nevermind

Thats wrong.
Total is Defined as the Value itself.

If we use total, We Need to get The Changed Signal of the Value Property in the DonateValue
and Not the Value inside of the ValueProperty.

I know this is hard to understand but i tried my best.

You have a variable named “total” that already gets the value.
The correct way will be:

donate.Changed:Connect(function()
	if donate.Value >= 1000000 then 
		...
	end
end)

or you could use :GetPropertyChangedSignal(), either way works.

1 Like