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

If statement won't work, but no error in the output?

Asked by
Manby7 32
3 years ago

I am trying to make a script so that when the value (parent of the Script), is true, a block of code fires. For some reason, when the value is true (I checked this by the way), the code does not fire. Also, the script is not in server storage, or any other place where a script won't run.

Here is my code:

if script.Parent.Value == true then
    print("Success")
    script.Parent.Parent.Parent = workspace
    script.Parent.Parent.Position = Vector3.new(-70.844, 45.947, -233.831)
    script.Parent.Parent.Position = Vector3.new(-0.28, 0.01, -2.68)
    workspace.tele1.Position = Vector3.new(-75.923, 37.99, -223.249)
    workspace.tele2.Position = Vector3.new(1368, -74.568, -53.679)
end
0
By the way, the script, its parent (which is an object) and its parent (a folder) are parented to Workspace. Manby7 32 — 3y
0
Can you explain what the script is supposed to do? LeedleLeeRocket 1257 — 3y
0
Its supposed to position a union a certain way. Manby7 32 — 3y
0
Your if-statement is evaluated upon runtime, it's not going to yield for you. If you want to run a block of code when the condition is met, you must wrap it in a callback passed to Instance:GetPropertyChangedSignal("Value"):Connect(Callback) Ziffixture 6913 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago

you can try

repeat
    wait()
until
script.Parent.Value == true
print("Success")
script.Parent.Parent.Parent = workspace
script.Parent.Parent.Position = Vector3.new(-70.844, 45.947, -233.831)
script.Parent.Parent.Position = Vector3.new(-0.28, 0.01, -2.68)
workspace.tele1.Position = Vector3.new(-75.923, 37.99, -223.249)
workspace.tele2.Position = Vector3.new(1368, -74.568, -53.679)
Ad
Log in to vote
0
Answered by
Xapelize 2658 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago

[REMEMBER TO MARK ME AS THE CORRECT ANSWER IF I HELPED TO FIX YOUR CODE, THANKS!]

-- Explanation --

Your if-statement will fire when the game runs. But not forever, it only fire once when game starts.

So if you want to fix this, a little lazy answer is loop the if-statement and fire it every 1 second.

while wait(1) do
    -- Your entire code
end

Note: The code will work, but it's not the best answer. You can try to research for more answer. Thanks for reading, and I hope this helped too! Best of the luck, bye!

Answer this question