Ad
Log in to vote
0

How To Open A Door At A Certain Value?

Asked by 13 days ago

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

Log in to vote
0
Answered by 13 days ago
Edited 13 days ago

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)
0
Thank you, it works, I will make sure to check if 5 is in a loop or a function. EmmaMallen 0 — 13d
0
If this works make sure to mark it as your answer so other developers / scripters know this is solved and your welcome. shadowstorm440 35 — 13d
0
OMG THANK YOU SO MUCH I LOOKED FOR THIS FOR 3 FRICKIN HOURS Mantery123 6 — 9d
Ad

Answer this question