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

Loading the player?

Asked by 8 years ago

So I've been trying to re - spawn the player after 1.8 seconds. Everything works fine the first time the player dies, but after that the player doesn't re - spawn at all. The script is server - side, and is located in the Workspace service.

game.Players.CharacterAutoLoads = false

game.Players.PlayerAdded:connect(function(player)
    print("hi")
    local SpawnLoc = Instance.new("Vector3Value", player)
    SpawnLoc.Name = "SpawnLocation"
    SpawnLoc.Value = game.Workspace.Spawn.Position
    player:LoadCharacter()
    player.Character.Torso.CFrame = CFrame.new(Vector3.new(0,5,0)) + player.SpawnLocation.Value
    player.Character.Humanoid.Died:connect(function()
        print("hi")
        wait(1.8)
        player:LoadCharacter()
        player.Character.Torso.CFrame = CFrame.new(Vector3.new(0,5,0)) + player.SpawnLocation.Value
    end)
end)

Is it that the .Died event of the Humanoid is broken or what. ****Now if you do post an answer, explain your script thourally and do not include any complex/unnecessary code that just makes the script longer. THX!!!

--------------EDIT----------------

Reply to MastaJames : So then why wouldn't this work?

game.Players.CharacterAutoLoads = false

game.Players.PlayerAdded:connect(function(player)
    print("hi")
    local SpawnLoc = Instance.new("Vector3Value", player)
    SpawnLoc.Name = "SpawnLocation"
    SpawnLoc.Value = game.Workspace.LobbySpawnLocation.Position
    player:LoadCharacter()
    player.Character.Torso.CFrame = CFrame.new(Vector3.new(0,5,0)) + player.SpawnLocation.Value
    player.CharacterAdded:connect(function(char)
        print("hi")
        repeat wait() until char:FindFirstChild("Humanoid") ~= nil
        char.Humanoid.Died:connect(function()
            print("hi")
            wait(1.8)
            player:LoadCharacter()
            player.Character.Torso.CFrame = CFrame.new(Vector3.new(0,5,0)) + player.SpawnLocation.Valu
        end)
    end)
end)
1
You need the CharacterAdded event to encase the Died function. This is due to your character resetting and providing a new humanoid each time you respawn. M39a9am3R 3210 — 8y
0
So basicly the died event is broken and usluss for my script LateralLace 297 — 8y
0
No, it's still useful. The problem is that only the first character is being connected to the event. After that, a new one is loaded and needs to be connected to it's own event. By using CharacterAdded, as M39a9am3R suggested, will convienently allow you to do this. BlackJPI 2658 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

There are two answers to this
The first answer assumes that CharacterAdded works properly, and just rearranges your code

game.Players.CharacterAutoLoads = false

game.Players.PlayerAdded:connect(function(player)
    print("hi")
    local SpawnLoc = Instance.new("Vector3Value", player)
    SpawnLoc.Name = "SpawnLocation"
    SpawnLoc.Value = game.Workspace.LobbySpawnLocation.Position
    player.CharacterAdded:connect(function(char)
        print("hi")
        repeat wait() until char:FindFirstChild("Humanoid") ~= nil
        char.Humanoid.Died:connect(function()
            print("hi")
            wait(1.8)
            player:LoadCharacter()
            player.Character.Torso.CFrame = CFrame.new(Vector3.new(0,5,0)) + player.SpawnLocation.Value;
        end)
    end)
    player:LoadCharacter()
    player.Character.Torso.CFrame = CFrame.new(Vector3.new(0,5,0)) + player.SpawnLocation.Value
end)

The second answer assumes that CharacterAdded is broken, and tries to get around it by cheating.

game.Players.CharacterAutoLoads = false
game.Players.PlayerAdded:connect(function(player)
local bindPlayerDeath
     bindPlayerDeath = function()
       wait(1.8)
       player:LoadCharacter()
       player.Character.Torso.CFrame = CFrame.new(Vector3.new(0,5,0)) + player.SpawnLocation.Value
        player.Character:WaitForChild("Humanoid").Died:connect(bindPlayerDeath);
    end;
    print("hi")
    local SpawnLoc = Instance.new("Vector3Value", player)
    SpawnLoc.Name = "SpawnLocation"
    SpawnLoc.Value = game.Workspace.LobbySpawnLocation.Position
    player:LoadCharacter()
    player.Character.Torso.CFrame = CFrame.new(Vector3.new(0,5,0)) + player.SpawnLocation.Value
        print("hi")
        repeat wait() until char:FindFirstChild("Humanoid") ~= nil
        char.Humanoid.Died:connect(bindPlayerDeath);
end)
0
Thx lunate. LateralLace 297 — 8y
Ad

Answer this question