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

Custom spawn problem?

So look, in my obby, I already used the 4 colored spawns ROBLOX made for us. Then I had to make my own spawns, by cloning one of them, and putting a script in it so you change teams when you touch one of my custom spawns.

But the problem is with my custom spawns. If you die, you don't spawn on the custom spawns, you just spawn in the middle of nowhere.

That is why I created this script:

game.Players.PlayerAdded:connect(function(plr)
	plr.Character.Humanoid.Died:connect(function(died)
		if plr.TeamColor == BrickColor.new("New Yeller") then
		
	
		wait(6)
		died.Parent:MoveTo(game.Workspace.Custom1.Position)
		elseif plr.TeamColor == BrickColor.new("Toothpaste") then
			wait(6)
			died.Parent:MoveTo(game.Workspace.SpecialSpawn2.Position)
		elseif plr.TeamColor == BrickColor.new("Pink") then
			wait(6)
			died.Parent:MoveTo(game.Workspace.Custom3.Position)
		else
			print("The player that died isn't on any of the custom spawn teams, so they weren't teleported")
			
		end
	end)
end)

It has an error. In output, it is saying this: 11:38:21.241 - Workspace.Script:2: attempt to index field 'Character' (a nil value) Help?

1 comment

1

You can still use Roblox's spawn system. There's tons of brickcolors, so just edit the TeamColor property of each spawn accordingly.

2 answers

The Humanoid.Died event doesn't have any parameters, so the "died" variable is nil. You should be using the CharacterAdded event so that it hooks up to the death event each time the player respawns.

game.Players.PlayerAdded:connect(function(plr)
	plr.CharacterAdded:connect(function(char)
		char:WaitForChild("Humanoid").Died:connect(function(died)
        		if plr.TeamColor == BrickColor.new("New Yeller") then
			        wait(6)
			        died.Parent:MoveTo(game.Workspace.Custom1.Position)
		        elseif plr.TeamColor == BrickColor.new("Toothpaste") then
	            		wait(6)
	            		died.Parent:MoveTo(game.Workspace.SpecialSpawn2.Position)
		        elseif plr.TeamColor == BrickColor.new("Pink") then
			         wait(6)
		                 died.Parent:MoveTo(game.Workspace.Custom3.Position)
		        else
		                 print("The player that died isn't on any of the custom spawn teams, so they weren't teleported")
			end
		end)
	end)
end)

One possibility is the fact the script is running before the character loads. Try adding this above line 2, and tell me what happens.

repeat wait() until plr.Character

This should hopefully resolve that error.


EDIT:

After looking at the wiki, which you can see here, we can disregard my previous answer, and incorporate their example:

game:GetService('Players').PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(character)
		character:WaitForChild("Humanoid").Died:connect(function()
			print(player.Name .. " has died!")
		end)
	end)
end)

Try using their example, and editing the main inside the Died event.

4 comments

0

Doesn't work. Let me check the output.

0

... Now it says that 'died' is a nil value. qq

0

Okay, so we resolved one issue. Let's take a look. I will edit my answer soon.

0

I have edited and included the wiki page for the Died event.

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