How do you change gravity for just one user?

(Using remote events and local scripts)

Thank you everyone! I’ve resolved this issue, all it needed was a check to make sure that the user touching the barrier was the local user.

I haven’t been on studio for a while but I’m sure you can just send a value you want through the remote event then In a local script you’ll change the workspace’s gravity to the received value

2 Likes

I’m using this code:

local remoteEvent = ReplicatedStorage.ChangeGravityEvent

local function playerjoined(player)
	local character = player.Character
	if character then
		local playerWorkspace = character.Parent
	end
end
local function onGravityChange(player, gravity)
	local character = player.Character
	if character then
		local playerWorkspace = character.Parent
		playerWorkspace.Gravity = gravity
	end
end

remoteEvent.OnServerEvent:Connect(onGravityChange)

Burt it’s changing the gravity for all users.

Add a VectorForce into the player you want to change the ‘gravity’ for.
The VectorForce can be set up to add to the upwards or downwards force at the center of mass if you want to decrease or increase their gravity.

2 Likes

This has been heavily overcomplicated. Use the following in a local script.

game.ReplicatedStorage.SetGravity.OnClientEvent:Connect(function(value)
     workspace.Gravity = value
end

From a server-sided Script, use the following.

local RE = game.ReplicatedStorage.SetGravity
RE:FireClient(player, value)
1 Like

I used that in a team test and it changed the gravity for all players.

Don’t use FireAllClients. Only fire the event for the player you want.

1 Like

I put it in a local script that activates a function inside of the local script, which changes the gravity

local function touched(hit)
	if runbefore == false then
		runbefore = true
			local character = hit.Parent
			local player = Players.LocalPlayer
			print(player)
			if player then
				print('yes')
				local object = workspace:FindFirstChild(player.Name)
				print(object)
				if object then
					local humanoid = object:FindFirstChild("Humanoid")
					if humanoid then
						changegravityGUI()
						workspace.Gravity = 0
					end
				end
			end
		
	end
end

If the initial detection is client sided, no server communication is necessary. Just do workspace.Gravity = x in the local script.

1 Like

I did do that, I’ve commented out the server side connection, SORRY I FORGOT TO ADD THE BIT WHERE I ACTUALLY CHANGE THE GRAVITY. I’m going to edit that.

In this video I had activated the gravity change and it had changed for me but it had also changed for FireFlame6910, (sorry video recording shows bad fps)

Is the touch event client side or server side? If it’s server sided, only fire the remote event for the player who touched it. If it’s client side, just set the gravity.

1 Like

The touched() event is in a local script

You never check if the character that touched the part is the Character of the current LocalPlayer, so it enables it if any characters touch the part.

1 Like

How do I get that?, I’m using the hit variable’s Parent as the character.

local player = Players.LocalPlayer
local function touched(hit)
	if runbefore == false then
		runbefore = true
		local character = hit.Parent
		if character and character == player.character then
			changegravityGUI()
			workspace.Gravity = 0
		end
	end
end
1 Like

Screenshot 2024-12-25 at 4.53.30 PM
Um.

So that would indicate that another player touched it, therefore you shouldn’t modify the gravity?

1 Like

LivignArt_SSN, is one of my avatar items. (that i’m wearing).

isn’t “hit” is the HumanoidRootPart?

1 Like

Then switch it to hit:FindFirstAncestorOfClass(“Model”) instead of hit.Parent. Didn’t realize your debounce was a one time use(which it really doesn’t need to be) because you never sent the full script.

1 Like