How to call function when variable changes?

I’m trying to call a function after my variable, “Game1” changes from 0 to 1.

local trigger = game.Workspace.Hall.trigger
local Tel1 = workspace.Stage1.Stage1Brick

local tsound =  -- roblox sound id
local Game1 = 0


local function triggered()
	print("Triggered")
	tsound:Play()
	wait(10)
	tsound:Stop()
end

local function FGame1()
	if Game1 == 1 then
		print("oh yeah")
	end
end


trigger.Touched:Connect(function(poop)
	if poop.Parent:FindFirstChild("Humanoid") then
		Game1 = 1
		local Character = poop.Parent
		Character:SetPrimaryPartCFrame(Tel1.CFrame)
		trigger.Parent = nil
		triggered()
	end
end)

Game1.Changed:Connect(FGame1())

I’m getting an error message saying:
Players.gubuyguy3.PlayerScripts.trigger:35: attempt to index number with ‘Changed’

You called it again, you only just need to change it to:

Game1.Changed:Connect(FGame1)

Your connection means your Game1 equals a number. This means your doing like 1.Changed:Connect

Try this

setmetatable(_G, {
  __newindex = function(t, k, v)
      if k == "a" then
          print("a changed")
      end
  end
})
a = 1
b = 1
a = 2

prints

a changed
a changed

on Lua: demo, can’t test in Studio right now

It’s the wrong way to go about things though. It’d be better to have a function dedicated to setting the value of the variable, and also calling any functions that need to be called when it does change.

Thanks for that.

That makes sense. I tried

Game1.Value.Changed:Connect

Still didn’t work.

No. I meant it as a example.

I am not sure what you are trying to accomplish. What is it?

I just want to call a function when Game1 changes from 0 to 1.

you should use a intvalue and you can use the .changed on it.