I’m trying to create a script that changes the gravity for only one specific player using a LocalScript inside StarterPlayerScripts, but it’s affecting all players as if it were a ServerScript. I don’t know how to fix this.
local part1 = game.Workspace:WaitForChild("partetest1")
local part2 = game.Workspace:WaitForChild("partetest2")
part1.Touched:Connect(function()
game.Workspace.Gravity = 10
end)
part2.Touched:Connect(function()
game.Workspace.Gravity = 190
end)
You need to check if the touched part belongs to the character of Players.LocalPlayer.
local Players = game:GetService("Players")
part1.Touched:Connect(function(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player == Players.LocalPlayer then
game.Workspace.Gravity = 10
end
end)
part2.Touched:Connect(function(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player == Players.LocalPlayer then
game.Workspace.Gravity = 190
end
end)
do you actually want all things locally have less gravity? because it may desync some parts physical interaction and positions among server and other clients.
if you only want the player character to have less gravity, you can instead create a VectorForce for their humanoid root part instead