I want to remove a script once a leaderstat is higher than 1, but it doesn’t work.
if money.Value > 1 then
game.Players.LocalPlayer.PlayerGUI.PlayScreen.Screen.Play.Cut1:Destroy()
end
I want to remove a script once a leaderstat is higher than 1, but it doesn’t work.
if money.Value > 1 then
game.Players.LocalPlayer.PlayerGUI.PlayScreen.Screen.Play.Cut1:Destroy()
end
You forgot to define money if that is the whole script and you didn’t add a changed function.
So for instance:
local plr = game.Players.LocalPlayer
local money = game.ReplicatedStorage.Money:WaitForChild(plr.Name)
money.Value.Changed:Connect(function()
if money.Value > 1 then
game.Players.LocalPlayer.PlayerGui.PlayScreen.Screen.Play.Cut1:Destroy()
end
end)
Try “PlayerGui” instead of “PlayerGUI”
Which script is it? If it’s a local script, you’ll need to do a remote event to destroy itself or a bindable event if it’s a normal script.
While wait() do
if money.Value > 1 then
game.Players.LocalPlayer.PlayerGui.PlayScreen.Screen.Play.Cut1:Destroy()
end
end
money.Changed:Connect(function()
if money.Value > 1 then
-- stuff here
end
end)
Why are you using a while wait()
loop?, don’t ever use while wait() do
. Just use money.Changed
.
Yes Maybe it will be better with :GetPropertyChangedSignal
Find More Here https://developer.roblox.com/en-us/api-reference/function/Instance/GetPropertyChangedSignal
You don’t need to use :GetPropertyChangedSignal("Value")
for ValueBase
objects as they have a modified .Changed
event that only fires when Value
property changes.
So Sometimes i used .Changed and got many problems thatswhy i am not trying to use it
I’ve never had a problem with .Changed
a possible reason why sometimes it doesnt work why your using .Changed
; maybe because you are trying to detect a change by doing NameOfInstance.Value.Changed
, instead of doing NameOfInstance.Changed
??
You have to do that from the client, create a LocalScript:
local player = game.Players.LocalPlayer
local leaderstats = player:WaitForChild("leaderstats") -- you need to wait until money is added
local money = leaderstats:WaitForChild("Money")
local PlayerGui = player.PlayerGui
local playScreen = PlayerGui:WaitForChild("PlayScreen")
money.Changed:Connect(function()
if money.Value > 1 then
playScreen.Screen.Play.Cut1:Destroy()
end
end)
Where do I put this localscript?
Where you normally put a localscript, in the StarterGui, StarterPack, StarterPlayerScripts or StarterCharacterScripts. You should use StarterGui.
This works, but only when it changes, I want it to do it as soon as the player enters the game.
Okay, then do this:
local player = game.Players.LocalPlayer
local leaderstats = player:WaitForChild("leaderstats") -- you need to wait until money is added
local money = leaderstats:WaitForChild("Money")
local PlayerGui = player.PlayerGui
local playScreen = PlayerGui:WaitForChild("PlayScreen")
money.Changed:Connect(function()
if money.Value > 1 then
playScreen.Screen.Play.Cut1:Destroy()
end
end)
if money.Value > 1 then
playScreen.Screen.Play.Cut1:Destroy()
end