Gravity script support

hello, I have had a little problem with this code, can someone help me?

the idea is this:

  • when you click on the button your gravity changes (to normal or no gravity).
local player = game.Players.LocalPlayer
local gravityEnabled = true 

local function toggleGravity()
	gravityEnabled = not gravityEnabled
	if gravityEnabled then
		player.Character.HumanoidRootPart.Gravity = 196.2 -- normal gravity
	else
		player.Character.HumanoidRootPart.Gravity = 0  -- after click
	end
end

local button = script.Parent

button.MouseButton1Click:Connect(function()
	toggleGravity()
end)

1 Like

Captura de Pantalla 2023-08-06 a la(s) 9.53.52 p.m.
this is how the script and its parents are composed

2 Likes

You Didn’t say what problems you have with it
Btw gravity is property of workspace

1 Like

that’s because Gravity is a property of workspace
replace

player.Character.HumanoidRootPart.Gravity

with

workspace.Gravity
1 Like