Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How To Open A Door At A Certain Value?

Asked by 3 years 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
3
Answered by 3 years ago
Edited 3 years 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 13 — 3y
0
If this works make sure to mark it as your answer so other developers / scripters know this is solved and your welcome. shadowstorm440 590 — 3y
0
OMG THANK YOU SO MUCH I LOOKED FOR THIS FOR 3 FRICKIN HOURS Mantery123 9 — 3y
Ad

Answer this question