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

Why isn't my variable 'PERMISSION' changing when the function is activated?

Asked by 5 years ago
Edited by Amiaa16 5 years ago

How come whenever I want to make it to where when I click on the specific block, it doesn't change the variable 'PERMISSION' to true? The only thing i'm needing it to do is change that variable inside of a function.

Thank you for your time

PERMISSION = false


script.Parent.ClickDetector.MouseClick:Connect(function(PERMISSIONGRANTED) 
    script.Parent.BrickColor = BrickColor.new ("Lime green")
    PERMISSION = true
end)

if PERMISSION == true then
    print("SCRIPT SUCCESSFUL")
end
0
please use code blocks theking48989987 2147 — 5y
0
If kiriot22 solves your problem don't forget to accept his answer User#24403 69 — 5y

1 answer

Log in to vote
0
Answered by
Amiaa16 3227 Moderation Voter Community Moderator
5 years ago

It does change the variable to true. The reason it doesn't print "SCRIPT SUCCESSFUL" is because you only check if the value is true once.

You can just put the print and the rest of the code after line 6, (after setting PERMISSION to true). That way you won't have to check if it's true, but rather do stuff straight away.

Btw, a little tip: use local variables.

local PERMISSION = false

script.Parent.ClickDetector.MouseClick:Connect(function(PERMISSIONGRANTED) 
    script.Parent.BrickColor = BrickColor.new ("Lime green")
    PERMISSION = true
    print("SCRIPT SUCCESSFUL")
    --stuff
end)

Ad

Answer this question