Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

My script fail when 2 players spawn at the same time... How can I fix this? [Solved]

I want to make a game similar with systems similar to hide and seek, minigames.

This includes killing off the winners after the minigame.

The players have costumes each time they spawn.

Let's say for a certain minigame there are 3 winners. After resetting the game (Which also means killing the winners for them to spawn), Problem: I notice that the costume for player 1 and player 2 are incomplete while only player 3 has a complete costume.

My assumption is that if players 1, 2, and 3 spawn at the same time. It does a bit of work into morphing player 1, but as soon as the character for player 2 loads, it stops morphing player 1 and morphs player 2, and again if the character for player 3 loads, it stops morphing player 2 and automatically starts for player 3.

Is there in any way, I can make a script that does this simultaneously.

Sadly, I can not provide you the script (Due to it being very long), however. A general term of the code is:

local loadmodule = script:WaitForChild("LoadPlayers")
local module = require(script.LoadPlayers)

game.Players.PlayerAdded:connect(function(Player)

	Player.CharacterAdded:Connect(module.LoadBody)

end

2 comments

1

Is the script is in ServerScriptService?

1

Providing the script would be better but from what i see you are calling module.LoadBody without any arguments so you are not getting character from this player from which i think there should be an argument which would be the player or his character.

2 answers

Hey there!

Could I just get you to check your LoadBody function, as that could be propagating the issue, otherwise- this should work!

local Players = game:GetService("Players")
local Load, Module = script:WaitForChild("LoadPlayers"), require(script.LoadPlayers)

Players.PlayerAdded:Connect(function(Player)
  if Player.Character then
    Module.LoadBody(Player.Character)
  end

  -- Rest of your Code
  Player.CharacterAdded:Connect(Module.LoadBody)
end)

I have fixed the script.

It was a simple case of:

My script editing the character before the character could load (which I thought was impossible).

This discussion is preserved as it was. New answers, comments, and votes are closed.