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

Door not doing anything when a value is is true?

Asked by 5 years ago

I am working on an easter game, and when you click on an egg, it is supposed to change a value to true, and then a door is supposed to open. Nothing happens when clicked and no errors. Here is the door's code.

1local WaterEggCollected = game.Workspace.Values.WaterEggCollected.Value
2local Door1 = game.Workspace.Door1
3while true do
4    if WaterEggCollected == true then
5        Door1.Transparency = 1
6        Door1.CanCollide = false
7    end
8end

Here is the egg code.

1function OnClicked (mouse)
2    script.Parent:Destroy()
3    game.Workspace.Values.WaterEggCollected.Value = true
4end
5script.Parent.ClickDetector.MouseClick:connect(OnClicked)

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

First, when you set WaterEggCollected = ....WaterEggCollected.Value, you set it to the value of the variable at that instant only. It does not update automatically if something changes the variable.

Second, by calling script.Parent:Destroy(), you remove the script's parent, which also destroys the script.

Third, your while loop really needs a wait().

Let me know if you have any more issues.

Ad

Answer this question