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

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

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 ?

1 comment

0

You could just simply make a conditional statement(if-then) to check if the character exists or not. 

1 answer

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

1 comment

0

how can i apply that ?

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