Value not being added to

Here is what I’m working with:

Two objects, One door, and an IntValue in the workspace
Both objects have to be open in order for the door to be unlocked, the door is checking if the IntValue located in the workspace = 2 in order to be unlocked.

But I can’t for the life of me figure out how I even add to the value in the first place.

Code inside the objects
same across both, so when both are opened, the IntValue should be at 2.

local SecretDoorValue = game.Workspace.CliffDoorValue.Value -- The value of the IntValue object
local Opened = false
local X = script.Parent:WaitForChild("Assembly")

local Prompt = script.Parent.Assembly.Top:WaitForChild("ProximityPrompt")

function OpenDoor()
	if Opened == false then
		Opened = true
		SecretDoorValue = SecretDoorValue + 1 -- Add to the IntValue's value
		Prompt.Enabled = false
		for i = 1, 54 do
			X:TranslateBy(Vector3.new(0, 0.08, 0))
			wait()
		end
		Prompt.ActionText=("Close")
		Prompt.Enabled = true
	else
		Opened = false
		SecretDoorValue = SecretDoorValue - 1 -- Subtract from the IntValue's value
		Prompt.Enabled = false
		for i = 1, 54 do
			X:TranslateBy(Vector3.new(0, -0.08, 0))
			wait()
		end
		wait()
		Prompt.ActionText=("Open")
		Prompt.Enabled = true
	end
end
Prompt.Triggered:Connect(function(Players)
	OpenDoor()
end)

My problem as of now is trying to actually add/subtract to the IntValue… nothing happens at all.

Script inside the door to be unlocked

local SecretDoorValue = game.Workspace.CliffDoorValue
local Door = script.Parent

if SecretDoorValue.Value == 2 then
	Door.ProximityPrompt.Enabled = true
elseif SecretDoorValue.Value ~= 2 then
	Door.ProximityPrompt.Enabled = false
end

Currently, you’re defining your variable SecretDoorValue, and every time you add or subtract, it adds to the variable, not the IntValue.

I would suggest:

local SecretDoorValue = game.Workspace.CliffDoorValue

And for the addition/subtraction lines:

SecretDoorValue.Value = SecretDoorValue.Value + 1

Ok, I implemented your suggestions, and now the value is finally being added to and subtracted from.

Now the next problem is trying to actually make the door’s script recognise when the value becomes 2 in order to enable the proximityprompt.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.