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

Why wont my door open when the value is 3? Can anyone explain?

Asked by
Cowgato 33
1 year ago
Edited 1 year ago

Essentially, I'm making a system where you need to collect 3 orbs to open a door. Once the value reaches 3, the door doesn't change for some reason. (AmountOfOrbs is a NumberValue in workspace)

--SCRIPT FOR THE DOOR--
if game.Workspace.AmountOfOrbs.Value == 3 then
    game.Workspace.Door.CanCollide = false
    game.Workspace.Door.Transparency = 0.25
end

(they are in separate scripts in workspace btw)

--SCRIPT FOR THE ORB--
script.Parent.Touched:Connect(function(hit)
    game.Workspace.AmountOfOrbs.Value +=1
    script.Parent:Destroy()
end)

1 answer

Log in to vote
1
Answered by 1 year ago
Edited 1 year ago

The first script doesn't get updated, it only runs once. To make it updated, use the Instance:GetPropertyChangedSignal() function/event and check if the new value is or more than 3.

workspace:WaitForChild("AmountOfOrbs"):GetPropertyChangedSignal("Value"):Connect(function()
    local newValue = workspace:WaitForChild("AmountOfOrbs").Value

    if newValue >= 3 then
        workspace.Door.CanCollide = false
workspace.Door.Transparency = 0.25
    end
end)
0
i think for a noob it's better to just merge the scripts together : ) imKirda 4491 — 1y
0
ValueBase instances are equipped with an overridden Instance.Changed event that responds solely to changes in their Value property. Callbacks of this event are also provided with the new state of said property.  Ziffixture 6913 — 1y
0
^^^ workspace.AmountOfOrbs.Changed:Connect(function(newValue) print("New value:", newValue) end) imKirda 4491 — 1y
Ad

Answer this question