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

How To Open A Door At A Certain Value?

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.

1 answer

✓ Accepted answer

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)

3 comments

0

Thank you, it works, I will make sure to check if 5 is in a loop or a function.

0

If this works make sure to mark it as your answer so other developers / scripters know this is solved and your welcome.

0

OMG THANK YOU SO MUCH I LOOKED FOR THIS FOR 3 FRICKIN HOURS

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