How do you change gravity for just one user?

(Using remote events and local scripts)

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

1 Like

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.

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)

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.

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.

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.

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.

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?

LivignArt_SSN, is one of my avatar items. (that iā€™m wearing).

isnā€™t ā€œhitā€ is the HumanoidRootPart?

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.