Script sometimes changes Bool variable (tested on multiple PCs)

The function is simply mean to change a single Bool value to false/true yet can’t
I have verified that the Open variable is able to find the bool and is even able to rename it and use :Destroy() on it successfully, yet changing Open.Value to true or false simple does nothing, no error or anything.

--Made by charlierw1

local TrapControl = game:GetService("ReplicatedStorage").TrapControl
local ScriptStorage = game:GetService("ServerScriptService")
local TrapModule = require(ScriptStorage.TrapModule) --for forum this is the module that creates the value that refuses to change (sometimes that is)
local TrapButton = script.Parent
local Map = TrapModule.Map
local TrapNumber = string.gsub(script.Parent.Name, "%D", "") --Set Variable as the number inside the button the script is in's name
local Open = workspace:FindFirstChild("Door" .. TrapNumber)

--Variable innit
function Trapsmit()
	Open.Value = true
end
TrapButton.MouseButton1Click:Connect(Trapsmit)
--Run function when button is clicked and released

The way the Open varialble is populated suggests the BoolValue is directly within the workspace and called Door1 or something similar, is that correct?

Have you verified that the Trapsmit method is actually being called?

1 Like

Yes the variable is called “Door1”, I have verified the code is being executed as I have replaced Open.Value = true with Open:Destroy() and Open.Name = “yeah” and in both instances it works, so I know that open is finding the correct thing. The only thing I have an issue with is changing the .Value of the Bool.

Are you using a Local or Server script?
Changing objects requires a Server script in order to replicate.

All scripts involved use a server script.

Try the following, check what prints and see if it’s correct.
Also changed the bool set at you were just setting to true every time.

function Trapsmit()
	print(“clicked”, Open, TrapNumber)
	Open.Value = not Open.Value
end
2 Likes

Just take every players position and calculate the change in there position once in anwhile and if its consistently exceptionally high either go ahead and kick them or monitor them more closely for things like acceleration travelling upwards

function Trapsmit()
	Open.Value = not Open.Value
	print(Open.Value)
end

Try this, it should toggle the BoolValue between true and false and then print that value, if you’re not seeing anything output in console then you likely have some replication issue.

1 Like

Apologies for responding a year later, I took a break for a while.

I tried what you suggested and it was all correct. (Printed clicked Door1 and 1) I also added one after to see if it had been changed and it had not.

local TrapControl = game:GetService("ReplicatedStorage").TrapControl
local ScriptStorage = game:GetService("ServerScriptService")
local TrapModule = require(ScriptStorage.TrapModule)
local TrapButton = script.Parent
local Map = TrapModule.Map
local TrapNumber = string.gsub(script.Parent.Name, "%D", "") --Set Variable as the number inside the button the script is in's name
local Open = workspace:WaitForChild("Door" .. TrapNumber) --Set Open as the variable the module script creates

--Variable innit
function Trapsmit()
	print("Button Clicked", Open, TrapNumber, Open.Value)
	Open.Value = true --Survivor is only able to activate the trap
	print(tostring(Open) .. " is set to " .. tostring(Open.Value))
end
TrapButton.MouseButton1Click:Connect(Trapsmit)
--Run function when button is clicked and released

As far as I am aware the variables used to define open are all correct as I can manipulate the variable in any way other than changing the value seemingly.

As it turns out there was another script changing the value that was connected to the value changing so the solution was me just being an idiot, although I did end up making my code more efficient while trying to find it so I guess it was a net positive.

Thanks to anyone who tried to help.

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