[DISCONTINUED] How would I use the "Instance.Changed" to replace wait(#) in my while true do script?

This post is discontinued. Scroll down to view the post before it was discontinued…
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

  1. What do you want to achieve? Keep it simple and clear!
    I want to fix my script so that I can replace “wait(#)” to an “Instance.Changed”.

  2. What is the issue? Include screenshots / videos if possible!
    I just want to change my script but I don’t want people to unnecessary wait for the boolvalue to change to true.

Also just as a note: I modified the script a little bit to now stop me from getting the “…not a member of PlayerGui” error.

  1. What solutions have you tried so far (scripts I have for you to see)? Did you look for solutions on the Developer Hub?
-- Local Script --
local LocalPlr = script.Parent.Parent
local PlayerModule = require(LocalPlr.PlayerScripts:WaitForChild("PlayerModule"))
local Controls = PlayerModule:GetControls()

while true do
	wait(0.05)
	if LocalPlr.PlayerGui:WaitForChild("AlreadyDid").Value == false then
		Controls:Disable()
	elseif LocalPlr.PlayerGui:WaitForChild("AlreadyDid").Value == true then
		Controls:Enable()
	end
end

Yes I do, but it went over my head a little bit…

Try researching the developer.roblox.com page:

For this scenario I recommend using the GetPropertyChangedSignal(str Property) function. This function is fired whenever the specified property of the instance is changed.

local LocalPlr = script.Parent.Parent
local PlayerModule = require(LocalPlr.PlayerScripts:WaitForChild("PlayerModule"))
local Controls = PlayerModule:GetControls()

local AlreadyDid = LocalPlr.PlayerGui:WaitForChild("AlreadyDid")

AlreadyDid:GetPropertyChangedSignal("Value"):Connect(function()
	if AlreadyDid.Value == false then
		Controls:Disable()
	else
		Controls:Enable()
	end
end)

2 Likes

Thank you for this solution. I’ll modify my script once again to fix what I’ve done…

1 Like