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.