Why Wont My Script Work?

So, I’m trying to make a border game with a set of doors to keep people out. I made a script that says as long as these two variables are working, the doors should work to, but when the variables are disabled, the doors open for people to rush in. This is so that there can be more ways to get in than the traditional way, however it doesn’t seem to work, I even asked Ai (not helpful but still I tried) and it couldn’t help me either. There are no errors, so I am confused.

Script Number 1: The One That Sets Up The System, it is called GateFunctioningScript

local Working1 = script.Working1
local Working2 = script.Working2
local DoorSystem = game.Workspace.Stuff.Border.Wall.Gate.DoorSystem

if Working1.Value == true and Working2.Value == true then
	
	DoorSystem.Door1Activatorlo.ProximityPrompt.Enabled = true
	DoorSystem.Door1Activatorlo.BrickColor = BrickColor.new("Gold")
	DoorSystem.Door2Activatorlo.ProximityPrompt.Enabled = true
	DoorSystem.Door1Activatorlo.BrickColor = BrickColor.new("Gold")

else
	
	DoorSystem.Door1.Transparency = 1
	DoorSystem.Door2.Transparency = 1
	DoorSystem.Door1.CanCollide = false
	DoorSystem.Door2.CanCollide = false
	DoorSystem.Door1Activatorlo.ProximityPrompt.Enabled = false
	DoorSystem.Door1Activatorlo.BrickColor = BrickColor.new("Maroon")
	DoorSystem.Door2Activatorlo.ProximityPrompt.Enabled = false
	DoorSystem.Door2Activatorlo.BrickColor = BrickColor.new("Maroon")
	
end

image

Script Number 2: A simple script that should just make the variables disable and = false.

script.Parent.Triggered:Connect(function()
	local working1 = game.ServerScriptService.GateFunctioningScript.Working1
	local working2 = game.ServerScriptService.GateFunctioningScript.Working2
	working1 = false
	working2 = false
end)

I would appreciate any help I can get!

you forgot to add .value afterwards since this is an instance and not a variable

shoot, that might be it lemme try that out. I recoded that last, smaller script and I might have forgot that in the first one. lemme see rq

1 Like

hmm no still doesnt work. and still no errors!!!

1 Like

Did you capitalize the V in value? I didn’t do it on accident.

Also, where’s script #2 located

add YourValue.Changed:Connect(function()

yeah i did… this is so strange idk whats happening

wait where do I add that? in the first or 2nd sript

it should be

local Working1 = script.Working1.Value
local Working2 = script.Working2.Value

same in the 2nd script

Yes, I forgot to write about this. first

that didnt seem to work, whats wrong with my scripit ;( lol

follow the steps @Goldzizd told you

wait do I just put it at the top of the script or just anywhere work?

local Working1 = script.Working1
local Working2 = script.Working2
local DoorSystem = game.Workspace.Stuff.Border.Wall.Gate.DoorSystem

Working1.Changed:Connect(function()
if Working1.Value == true and Working2.Value == true then

	DoorSystem.Door1Activatorlo.ProximityPrompt.Enabled = true
	DoorSystem.Door1Activatorlo.BrickColor = BrickColor.new("Gold")
	DoorSystem.Door2Activatorlo.ProximityPrompt.Enabled = true
	DoorSystem.Door1Activatorlo.BrickColor = BrickColor.new("Gold")

else

	DoorSystem.Door1.Transparency = 1
	DoorSystem.Door2.Transparency = 1
	DoorSystem.Door1.CanCollide = false
	DoorSystem.Door2.CanCollide = false
	DoorSystem.Door1Activatorlo.ProximityPrompt.Enabled = false
	DoorSystem.Door1Activatorlo.BrickColor = BrickColor.new("Maroon")
	DoorSystem.Door2Activatorlo.ProximityPrompt.Enabled = false
	DoorSystem.Door2Activatorlo.BrickColor = BrickColor.new("Maroon")

end

end)

Wait oh shoot yeah I didn’t notice that it only runs thru once, @Goldzizd should have the right answer

1 Like

Sorry for writing with mistakes, I am writing in a hurry

1 Like

It looks like you have a script setup for a gate system in a Roblox game where doors are controlled based on the values of two variables (Working1 and Working2). The first script, GateFunctioningScript, checks these variables to determine if the doors should be active or not. The second script is meant to disable these variables when triggered. However, there are a few potential issues that could be causing the gate system to not behave as expected:

Key Issues:

  1. Variable Handling in Script 2: In Script 2, you’re trying to set working1 and working2 to false, but you’re only changing the variable references, not the actual Value properties of the variables. If Working1 and Working2 are BoolValue objects, you should set their .Value properties, like so: working1.Value = false and working2.Value = false.

  2. Initial Script Execution: The logic in GateFunctioningScript runs once when the script is first executed. If the values of Working1 and Working2 change after this script runs, the changes won’t affect the gate’s state unless the script is run again or unless you set up connections to value changes.

Suggested Fixes:

  1. Correct the Value Assignment in Script 2:
    Modify the second script to set the Value property of the BoolValue objects:
    script.Parent.Triggered:Connect(function()
        local working1 = game.ServerScriptService.GateFunctioningScript.Working1.Value
        local working2 = game.ServerScriptService.GateFunctioningScript.Working2.Value
        working1.Value = false
        working2.Value = false
    end)
    
  2. Add Connections to Value Changes in Script 1: To ensure that the doors update immediately when Working1 or Working2 changes, you can connect functions to the Changed events of these variables. Here’s how you can modify GateFunctioningScript:
local Working1 = script.Working1.Value
local Working2 = script.Working2.Value
local DoorSystem = game.Workspace.Stuff.Border.Wall.Gate.DoorSystem

local function UpdateDoors()
    if Working1.Value == true and Working2.Value == true then
        DoorSystem.Door1Activatorlo.ProximityPrompt.Enabled = true
        DoorSystem.Door1Activatorlo.BrickColor = BrickColor.new("Gold")
        DoorSystem.Door2Activatorlo.ProximityPrompt.Enabled = true
        DoorSystem.Door2Activatorlo.BrickColor = BrickColor.new("Gold")
    else
        DoorSystem.Door1.Transparency = 1
        DoorSystem.Door2.Transparency = 1
        DoorSystem.Door1.CanCollide = false
        DoorSystem.Door2.CanCollide = false
        DoorSystem.Door1Activatorlo.ProximityPrompt.Enabled = false
        DoorSystem.Door1Activatorlo.BrickColor = BrickColor.new("Maroon")
        DoorSystem.Door2Activatorlo.ProximityPrompt.Enabled = false
        DoorSystem.Door2Activatorlo.BrickColor = BrickColor.new("Maroon")
    end
end

-- Connect the function to the Changed event of the variables
Working1.Changed:Connect(UpdateDoors)
Working2.Changed:Connect(UpdateDoors)

-- Run the function once at the start to set initial state
UpdateDoors()
3 Likes

The long reply above is correct. GateFunctioningScript is a one time run script that will happen at the start of the game and never again. Your Triggered:Connect() function changes the values of working1 and working2 but doesn’t do anything else. You should put the if else block from GateFunctioningScript into a function and call it from inside Triggered:Connect().

It still won’t work because you can’t access a function from another script. So you need to move them to the same script. And call the function one time inside the script so that it sets the initial state.

1 Like

I moved the thing you told me to into the bigger script, here is the larger script so far

local Working1 = script.Working1
local Working2 = script.Working2
local DoorSystem = game.Workspace.Stuff.Border.Wall.Gate.DoorSystem

Working1.Changed:Connect(function()
	if Working1.Value == true and Working2.Value == true then

		DoorSystem.Door1Activatorlo.ProximityPrompt.Enabled = true
		DoorSystem.Door1Activatorlo.BrickColor = BrickColor.new("Gold")
		DoorSystem.Door2Activatorlo.ProximityPrompt.Enabled = true
		DoorSystem.Door1Activatorlo.BrickColor = BrickColor.new("Gold")

	else

		DoorSystem.Door1.Transparency = 1
		DoorSystem.Door2.Transparency = 1
		DoorSystem.Door1.CanCollide = false
		DoorSystem.Door2.CanCollide = false
		DoorSystem.Door1Activatorlo.ProximityPrompt.Enabled = false
		DoorSystem.Door1Activatorlo.BrickColor = BrickColor.new("Maroon")
		DoorSystem.Door2Activatorlo.ProximityPrompt.Enabled = false
		DoorSystem.Door2Activatorlo.BrickColor = BrickColor.new("Maroon")

	end
end)

game.Workspace.Heafty.ProximityPrompt.Triggered:Connect(function()
	local working1 = game.ServerScriptService.GateFunctioningScript.Working1.Value
	local working2 = game.ServerScriptService.GateFunctioningScript.Working2.Value
	working1 = false
	working2 = false
end)

still, for some reason it did not work. There is still no error… im so confused

game.Workspace.Heafty.ProximityPrompt.Triggered:Connect(function()
    local working1 = game.ServerScriptService.GateFunctioningScript.Working1
    local working2 = game.ServerScriptService.GateFunctioningScript.Working2
    working1.Value = false
    working2.Value = false
end)