Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to always check if value is a specific variable until it reaches that variable?

Asked by 6 years ago

I'm trying to make a script keep checking a part's transparency frequently.. The part's default transparency is zero, and another script is coded to change the transparency to 1. The main script is supposed to constantly check what the transparency is, and once it finds out the transparency is 1, it'll stop checking. How do I do this? (Just so you know, the transparency checker script is a local script)

I try writing this:

if workspace.Part.Transparency == 1 then
    --enter action here
end

It obviously doesn't work because the script runs when the player spawns, and it only checks once.

1 answer

Log in to vote
0
Answered by
Radstar1 270 Moderation Voter
6 years ago
Edited 6 years ago

You can spawn a function that uses a while loop to check. In my opinion it's better to spawn a function instead of using a while loop because you can keep using the rest of the script even while the loop is running.

Then use a .Changed event to check to see each time if the transparency has changed.

local x = 1  -- So you can break the function whenever you want, just set x to another value.  
spawn(function()
    workspace.Smoke.Changed:Connect(function()
        while x == 1 do
            wait()
            if workspace.Smoke.Transparency == 1 then
                workspace.Smoke.Transparency = 0
            else
                return
            end
        end
    end)
end)
0
??? This is silly. This creates a new loop every time smoke changes! XAXA 1569 — 6y
0
yeah i thought about it was I being super extra, it'd be better to just do a .Changed event and leave it at that. Radstar1 270 — 6y
Ad

Answer this question