Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do you make it so a button can change your gravity?

i'm not sure how but this is what I tried.

script.Parent.MouseButton1Click:connect(function()
	if game.Workspace.Gravity == 196.2 then
		game.Workspace.Gravity = 60
	else
		game.Workspace.Gravity = 196.2
	end
end)

6 comments

0

Connect NOT connect

0

It doesn't seem like there is anything inherently wrong with this code. Where are you running it? What does your hierarchy look like?

0

StarterGui>Gamepasses>MoonGravityGui>Button

0

You cannot change the gravity of the workspace within a local script. I recommend using a remote event (https://wiki.roblox.com/index.php?title=Remote_Functions_%26_Events)

0

You CAN change workspace gravity from a LocalScript, and it will change only that client's gravity. What behavior do you want OP, do you want to change everyone's gravity or just the gravity of LocalPlayer.

0

Just the LocalPlayer

1 answer

✓ Accepted answer

This is a filtering issue. Set it on the server through a remote event:

--Local script

local remote = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")

script.Parent.MouseButton1Click:Connect(function()
   remote:FireServer()
end)


--Server script

local remote = Instance.new("RemoteEvent")
remote.Parent = game:GetService("ReplicatedStorage")

remote.OnServerEvent:Connect(function(plr)
   if workspace.Gravity == 196.2 then
      workspace.Gravity = 60
   elseif workspace.Gravity == 60 then
      workspace.Gravity = 196.2
   end
end)

Resources:

Remote Events

Accept and upvote if this helped!

This discussion is preserved as it was. New answers, comments, and votes are closed.