local gravitymodule = require(game.ServerStorage.GravityModule)
local space = game.Workspace.Space
local _space = {}
for _, v in pairs(space:GetChildren()) do
table.insert(_space, v)
end
for _, v in pairs(_space) do
for _, w in pairs(_space) do
if v ~= w then
if v:FindFirstChild("Humanoid") then
gravitymodule.addForce(v.LowerTorso, w)
else
gravitymodule.addForce(v, w)
end
end
end
table.remove(_space, table.find(_space, v))
end
function addInstance(x)
local _space = {}
for _, v in pairs(space:GetChildren()) do
table.insert(_space, v)
end
for _, v in pairs(_space) do
if v ~= x then
gravitymodule.addForce(x, v)
end
end
end
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAppearanceLoaded:Connect(function(char)
char.Animate.idle:Destroy()
char.Parent = game.Workspace.Space
char.Humanoid:ChangeState(Enum.HumanoidStateType.Physics)
local _space = {}
for _, v in pairs(space:GetChildren()) do
table.insert(_space, v)
end
for _, v in pairs(_space) do
if v ~= char then
gravitymodule.addForce(char.LowerTorso, v)
end
end
print("asdf")
end)
end)
Everything runs fine until the PlayerAdded event. Nothing after than runs. This script is in ServerScriptService.
It’s supposed to simulate gravity, using lineforces. The last part is supposed to check when a new player joins to add it’s character and simulate gravity for IT also. It doesn’t even print "asdf".
The player might be joining before you connect to PlayerAdded (mainly studio)
A solution to this would be to make a PlayerAdded function.
We then connect Players.PlayerAdded to this new function and we loop through all currently connected users and fire PlayerAdded.
I also now check inside of PlayerAdded incase the Appearance had loaded before we listened onto CharacterAppearanceLoaded
local function PlayerAdded(plr)
local function AppearanceLoaded(char)
char.Animate.idle:Destroy()
char.Parent = game.Workspace.Space
char.Humanoid:ChangeState(Enum.HumanoidStateType.Physics)
local _space = {}
for _, v in pairs(space:GetChildren()) do
table.insert(_space, v)
end
for _, v in pairs(_space) do
if v ~= char then
gravitymodule.addForce(char.LowerTorso, v)
end
end
print("asdf")
end
plr.CharacterAppearanceLoaded:Connect(AppearanceLoaded)
if plr:HasAppearanceLoaded() then
AppearanceLoaded(plr.Character)
end
end
game.Players.PlayerAdded:Connect(PlayerAdded)
for _,Player in ipairs(game.Players:GetPlayers()) do
task.spawn(PlayerAdded, Player)
end
Did you do that with your old code but with nothing inside? If yes, something inside of PlayerAdded is yielding the code. (Most likely to do with gravitymodule.addForce)
I think you were right. It was ok all the way until the modulescript loop. I’m guessing it stopped because of errors, but it didn’t say so… weird. I’m still looking into it, though. I’ll give you an update.