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

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

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

✓ Accepted answer

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)

3 comments

0

i think for a noob it's better to just merge the scripts together : )

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. 

0

^^^ workspace.AmountOfOrbs.Changed:Connect(function(newValue) print("New value:", newValue) end)

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