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

Custom spawn problem?

Asked by 9 years ago

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
You can still use Roblox's spawn system. There's tons of brickcolors, so just edit the TeamColor property of each spawn accordingly. Perci1 4988 — 9y

2 answers

Log in to vote
2
Answered by
Merely 2122 Moderation Voter Community Moderator
9 years ago

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)

Ad
Log in to vote
0
Answered by 9 years ago

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.

0
Doesn't work. Let me check the output. groovydino 2 — 9y
0
... Now it says that 'died' is a nil value. qq groovydino 2 — 9y
0
Okay, so we resolved one issue. Let's take a look. I will edit my answer soon. AmericanStripes 610 — 9y
0
I have edited and included the wiki page for the Died event. AmericanStripes 610 — 9y

Answer this question