I wrote this script which is supposed to open a Gui if a variable is a certain thing when clicking T.
If the variable isn’t the certain thing, then it would send a RemoteEvent to the server.
The variable is supposed to change depending on if you click on the button or not.
Well, the issue here is that whenever the script executes and whenever the button gets clicked on, the variable is changing. But whenever the Gui opens, the variable still stays the same as it was in the first instance. Making it always open the Gui and never sending the RemoteEvent even when the variable is supposed to change.
I’ve tried looking over the devforum for similar problems, and rewriting the script multiple times, but it never worked and the results were all the same. I’ve set print(variable) in the scripts and this is the output:

I assume that the variable isn’t updating in the script which means it’s still storing the old variable.
By the way, status is the variable we are talking about.
Here is the script:
local button = script.Parent
local Event = game.ReplicatedStorage.Transform
local rs = game:GetService("ReplicatedStorage")
local osound = rs.Music.OmnitrixSound
local GUI = script.Parent.Parent.Parent
local status = "normal" --sets status to normal at begin of script
local ContextActionService = game:GetService("ContextActionService")
local function onActivated()
if game.Workspace.InCombat.Value == false then
status = "custom" --changes status to custom (not normal)
print(status) --prints custom
Event:FireServer("DiamondHead")
GUI.Enabled = false
else
print("You're Currently in combat!")
end
end
button.Activated:Connect(onActivated)
local UIS = game:GetService("UserInputService")
--i assume here is the problem
UIS.InputBegan:Connect(function(Input, IsTyping)
if IsTyping then end
if Input.KeyCode == Enum.KeyCode.T then
if status == "normal" then --checks if status normal
if GUI.Enabled == false then
osound:Play()
GUI.Enabled = true
else osound:Play()
GUI.Enabled = false end end
print(status) --prints normal for some reason when status was changed to custom earlier in script
else if status == "custom" then --if not status is normal (doesnt happen, it always stays on normal??)
Event:FireServer("Reset")
status = "normal" end --changes back to normal status
end end)
This is a localscript located in a textbutton btw.
How can i let the variable get across the script better?
Could anyone explain to me what I did wrong or what I can improve? Thanks.