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
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)
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:
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.
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:
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)
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()
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.