I'm making a maze horror game, and you need to collect 5 objects to win the game, but my script has an error that i just can't see.
local orbs = game.Workspace.Orbs local OrbsCollected = game.ReplicatedStorage.OrbsCollected orbs.RedOrb.o4.Touched:Connect(function(hit) if game.Players:GetPlayerFromCharacter(hit.Parent) then OrbsCollected.Value = OrbsCollected.Value + 1 orbs.RedOrb:Destroy() end end) orbs.YellowOrb.o5.Touched:Connect(function(hit) if game.Players:GetPlayerFromCharacter(hit.Parent) then OrbsCollected.Value = OrbsCollected.Value + 1 orbs.YellowOrb:Destroy() end end) orbs.GreenOrb.o1.Touched:Connect(function(hit) if game.Players:GetPlayerFromCharacter(hit.Parent) then OrbsCollected.Value = OrbsCollected.Value + 1 orbs.GreenOrb:Destroy() end end) orbs.PurpleOrb.o2.Touched:Connect(function(hit) if game.Players:GetPlayerFromCharacter(hit.Parent) then OrbsCollected.Value = OrbsCollected.Value + 1 orbs.PurpleOrb:Destroy() end end) orbs.BlueOrb.o3.Touched:Connect(function(hit) if game.Players:GetPlayerFromCharacter(hit.Parent) then OrbsCollected.Value = OrbsCollected.Value + 1 orbs.BlueOrb:Destroy() end end) if OrbsCollected.Value == 5 then game.Workspace.WinDoor:Destroy() end
When you reach 5 on the int value, the door still doesn't open for some reason. I don't really see the error here. Help would be appreciated.
Your error is, your not checking if it's 5 in a loop or function
here's a simple fix:
OrbsCollected:GetPropertyChangedSignal("Value"):Connect(function() if OrbsCollected.Value == 5 then game.Workspace.WinDoor:Destroy() end end)
alternatively you can use this method too:
OrbsCollected.Changed:Connect(function() if OrbsCollected.Value == 5 then game.Workspace.WinDoor:Destroy() end end)