Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

i have a conflict with 2 scripts , any idea to fix it ?

Asked by 5 years ago

I have a little conflict with scripts, I recently put a script on my game that allows to extend the respawn time, but the problem is that this script uses this :

game.Players.CharacterAutoLoads = false

this is what allows the script to choose when to reappear, but the problem is that another one of my scripts conflicts and displays this error

23:08:27.845 - Workspace.SONIC.StatusChasing.Attack:40: attempt to index field'Character' (a nil value)

here is the line of code that is causing the problem :


for i,v in pairs(game.Players:GetChildren()) do local range = (v.Character.HumanoidRootPart.Position - Torso.Position).magnitude

any suggestions ?

0
You could just simply make a conditional statement(if-then) to check if the character exists or not.  User#20279 0 — 5y

1 answer

Log in to vote
0
Answered by
xPolarium 1388 Moderation Voter
5 years ago

What are you doing to extend respawn time?

A better way than messing with the AutoCharacterLoads is using the Died event from a Humanoid. If you have the player defined then you can load their character at any time using :LoadCharacter().

--After 5 seconds, the player character will load.
humanoid.Died:Connect(function()                        
    wait(5)
    player:LoadCharacter()
end)

You can have this in a PlayerAdded event function that will give you the player.

As for the second code piece provided. You should use :GetPlayers() over the children method.

for i,v in pairs(game.Players:GetPlayers()) do
    --Only our players would be acquired in player service.
    print(v.Name)
end
0
how can i apply that ? sheppard929 9 — 5y
Ad

Answer this question