And I Want Multiple Players Get Affected By The Gravity Aka LineForce.
And Yes Im Using One LineForce To Make The Script.
local affectedbygravity = false
game.Players.PlayerAdded:Connect(function(plr)
local oldplr = plr
local core = script.Parent
local char = plr.Character or plr.CharacterAdded:Wait()
local hrp = char.HumanoidRootPart
local lf = script.Parent.LineForce
local mag = (core.Position - char.HumanoidRootPart.Position).Magnitude
local maxmag = 500 -- Change this to whatever you want
if plr ~= oldplr then
local newplr = plr
end
while task.wait(0.1) do
local mag = (core.Position - char.HumanoidRootPart.Position).Magnitude
print(mag)
if mag > maxmag then
affectedbygravity = false
plr.PlayerGui.PlanetDesc.PlanetName.Text = "Planet Name"
plr.PlayerGui.PlanetDesc.PlanetDesc.Text = "Planet Description"
lf.Attachment0 = nil
lf.Attachment1 = script.Parent.Attachment
lf.MaxForce = 3500 -- Change this to whatever you want
else
affectedbygravity = true
lf.Attachment0 = hrp.RootAttachment
lf.Attachment1 = script.Parent.Attachment
lf.MaxForce = 3500 -- Change this to whatever you want
end
end
if affectedbygravity == true then
task.spawn(function()
game.ReplicatedStorage.PlanetRemote:FireClient(plr, "Earth.", "The Self Destroying Planet, Home To Every Human And Animal,")
end)
end
end)
Can you please be clear about your issue? So far you’ve only told us the things about the game, like force, and code but you never tell us the underlying issue
Nevermind I misread… You should create a new force for every player affected by gravity. Right now it just parents to one player explaining why it only affected one player
local affectedbygravity = false
game.Players.PlayerAdded:Connect(function(plr)
local oldplr = plr
local core = script.Parent
local char = plr.Character or plr.CharacterAdded:Wait()
local hrp = char.HumanoidRootPart
local lf = Instance.new("LineForce")
lf.MaxForce = 3500
lf.Attachment0 = plr.CharacterAppearanceLoaded:Wait():FindFirstChild("HumanoidRootPart")
lf.Attachment1 = script.Parent.Attachment
lf.Enabled = false
local mag = (core.Position - char.HumanoidRootPart.Position).Magnitude
local maxmag = 500 -- Change this to whatever you want
if plr ~= oldplr then
local newplr = plr
end
while task.wait(0.1) do
local mag = (core.Position - char.HumanoidRootPart.Position).Magnitude
print(mag)
if mag > maxmag then
affectedbygravity = false
plr.PlayerGui.PlanetDesc.PlanetName.Text = "Planet Name"
plr.PlayerGui.PlanetDesc.PlanetDesc.Text = "Planet Description"
lf.Enabled = false
else
affectedbygravity = true
lf.Enabled = true
end
end
if affectedbygravity == true then
task.spawn(function()
game.ReplicatedStorage.PlanetRemote:FireClient(plr, "Earth.", "The Self Destroying Planet, Home To Every Human And Animal,")
end)
end
end)
local RS = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local PlanetRemote = RS.PlanetRemote
local Core = script.Parent
local MaxMag = 500
Players.PlayerAdded:Connect(function(player: Player)
local Character = player.Character or player.CharacterAppearanceLoaded:Wait()
local Hrp = Character.HumanoidRootPart
local affectedbygravity = false
local Previous = nil
local Lf = Instance.new("LineForce")
Lf.MaxForce = 3500
Lf.Attachment0 = Hrp.RootAttachment
Lf.Attachment1 = Core.Attachment
while task.wait(0.1) do
local Mag = (Core.Position - Hrp.Position).Magnitude
print(Mag)
affectedbygravity = (Mag <= MaxMag) and true or false
if affectedbygravity == Previous then continue end
if affectedbygravity then
Lf.Enabled = true
PlanetRemote:FireClient(player, "Earth.", "The Self Destroying Planet, Home To Every Human And Animal.")
else
Lf.Enabled = false
PlanetRemote:FireClient(player, "Planet Name.", "Planet Description")
end
Previous = affectedbygravity
end
end)