Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
3

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

Asked by 5 years ago

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)
0
Connect NOT connect WideSteal321 773 — 5y
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? SummerEquinox 643 — 5y
0
StarterGui>Gamepasses>MoonGravityGui>Button User#23357 0 — 5y
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) McRocketNuggets 65 — 5y
View all comments (2 more)
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. SummerEquinox 643 — 5y
0
Just the LocalPlayer User#23357 0 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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!

Ad

Answer this question