Separate player only gravity applied to nearby blocks bug

I have discovered a script for a game I am working on, I have taken it from the “Changing gravity for only one player” discussion, the script works, but has glitches which make it unusable for my game.

The two main problems are, the blocks near the player receives the player’s gravity, I haven’t tested if it happens in a published game, or affects other players, but it most likely does, seemingly over time blocks further and further away are affected by it and after a few minutes it reaches the radius of hundreds of studs, which of course cannot be ignored. The second problem is that the blocks are not affected by a different script that is used to push blocks in a specific direction by applying Velocity to them. For context I am trying to create my own gravity for a space simulator game. I cannot find any other scripts which could replace it and I REALLY need it to finish the project. The script that applies Velocity to objects does not work on the player tho as the game has a modified Gravity Controller which allows the player to walk on any surface with a specific name, that is the reason for which I need the script that gives each and every player a different gravity.

Script of the glitched system I have problems with (put in StarterPlayerScripts as a LocalScript, it can also have different profiles):

wait()
local player = game.Players.LocalPlayer

game.Workspace.MoonGravity.Touched:Connect(function(hit)
	if hit == nil then return end
	if hit.Parent == nil then return end
	local hum = hit.Parent:FindFirstChild("Humanoid")
	if hum ~= nil then
		if game.Players:GetPlayerFromCharacter(hum.Parent) == player then
			game.Workspace.Gravity = 30
		end
	end
end)

game.Workspace.NormalGravity.Touched:Connect(function(hit)
	if hit == nil then return end
	if hit.Parent == nil then return end
	local hum = hit.Parent:FindFirstChild("Humanoid")
	if hum ~= nil then
		if game.Players:GetPlayerFromCharacter(hum.Parent) == player then
			game.Workspace.Gravity = 196.2
		end
	end
end)

Here’s the script that applies Velocity to blocks only:

script.Parent.Touched:Connect(function(hit)
	float = Instance.new("BodyVelocity",hit)
	float.MaxForce = Vector3.new(0,hit:GetMass()*-200,0)
	float.Velocity = Vector3.new(0,10,0)
	float.Name = "WaterFloat"
	if hit.Velocity.Magnitude >= 30 then
	splash = script.Parent.Splash:Clone()
	splash.Name = "Splash"
	splash.Parent = hit
	splash.Enabled = true
	splash.AutomaticToggle.Disabled = false
	if hit.Velocity.Magnitude >= 220 then
		hit:BreakJoints()
	end
	end
end)
script.Parent.TouchEnded:Connect(function(hit)
	hit.WaterFloat:Destroy()
end)

Here are the separate parts and the script which applies force to the player, you can download and test it if you wish, I recommend putting the world in 0 gravity and have some unanchored blocks floating around, to see that over time they also receive the gravity:

gravity blocks.rbxm (2.9 KB)

I am thankful for any help.

1 Like

Where is your second script located?

1 Like

The one which applies velocity to the blocks is located within a block in the workspace, it applies said velocity to any block that touches it, and removes the velocity when the touch breaks, it also has a splash particle, and within it is a second script.
Said script:

wait(0.2)
script.Parent.Enabled = false
wait(1.9)
script.Parent:Destroy()

Not an answer but

I read somewhere on roblox documentation or somewhere about network ownership. It mentioned nearby parts having their physics simulated on the closest player’s client while further stuff are calculated by the server.

I assumed this was outdated as it seemed very exploitable but perhaps it is still used and related? I also do not recall much of what i read bare in mind.

1 Like

I did ask about this somewhere else and apparently that is the cause of this problem, I am currently looking for an other method that could fix this issue.

Perhaps you can manually set the network ownership of nearby/all blocks to the server by reading up on SetNetworkOwnership()

Else disable gravity and write your own gravity script which applies a downwards force to all parts but the players on the server side, just ideas

1 Like

I did hear about the possibility of setting the network ownership of all blocks to the server but it supposedly results in weird and glitchy colissions between players and the blocks, still I will try to do so to see how bad it is going to be, and if it will fix the issue- if I do find a script that does that of course.

1 Like

I did find this which does provide a script and some other possible methods of fixing said issue!

1 Like

Another way of getting rid of NetworkOwnership on parts would be to anchor and CFrame them.
Anchored Parts don’t suffer that issue because they are owned by the server.
If it’s a gravity type game it shouldn’t be too difficult to CFrame and Tween them in a direction until they hit another item.

I will see if such a method if going to work, but I am not certain if it’s exactly what I am going for, I pretty much want to make planets with their own gravity all around them and also spaceships that can rotate in any direction and fly anywhere, everything being unanchored and so on, but of course not too much of that to avoid lag. It’s going to be a very simple demo at first but I will expand it into a more enjoyable game, of course the areas and planets won’t be like, big, due to Floating Point Errors which are very noticable.