Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Door not doing anything when a value is is true?

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.

local WaterEggCollected = game.Workspace.Values.WaterEggCollected.Value
local Door1 = game.Workspace.Door1
while true do
	if WaterEggCollected == true then
		Door1.Transparency = 1
		Door1.CanCollide = false
	end
end

Here is the egg code.

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

1 answer

✓ Accepted answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.