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.
1 | local WaterEggCollected = game.Workspace.Values.WaterEggCollected.Value |
2 | local Door 1 = game.Workspace.Door 1 |
3 | while true do |
4 | if WaterEggCollected = = true then |
5 | Door 1. Transparency = 1 |
6 | Door 1. CanCollide = false |
7 | end |
8 | end |
Here is the egg code.
1 | function OnClicked (mouse) |
2 | script.Parent:Destroy() |
3 | game.Workspace.Values.WaterEggCollected.Value = true |
4 | end |
5 | script.Parent.ClickDetector.MouseClick:connect(OnClicked) |
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.