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

This script makes my character die and respawn continuously, why?

Asked by 7 years ago
Edited 7 years ago

Here is the code, I'm not sure if I need to add debounce to it, or what the problem is. When I use it on a custom model when I spawn in I die instantly, and then I respawn, die. Continuously. When used with a dummy model from animation editor, I spawn in the middle of the map, not my spawn point, and am stuck in the air, unable to move. Any advice would be greatly appreciated. Here is the code:

local char = game.ServerStorage.CustomCharacter -- The character to load
local respawnTime = 2.5 -- How many seconds the player remains dead before they respawn

game.Players.CharacterAutoLoads = false -- Disable default character loading

function playerAdded(player)
    if player.Character and player.Character.Parent then -- Destroy an already-existing character
        player.Character:Destroy()
    end

    while player.Parent do -- Repeat until they leave the game
        loadChar(player) -- Method waits until they die
        wait(respawnTime)
    end
end

function loadChar(player)
    local char = char:clone()
    char.Name = player.Name

    local humanoid
    for i, child in pairs(char:GetChildren()) do -- Find the humanoid
        if child.ClassName == "Humanoid" then
            humanoid = child
            break
        end
    end

    if not humanoid then -- If no humanoid was found, make one
        humanoid = Instance.new("Humanoid", char)
    end

    player.Character = char
    char.Parent = game.Workspace
    humanoid.Died:wait() -- Wait until they die
end

game.Players.PlayerAdded:connect(playerAdded)

for i, player in pairs(game.Players:GetPlayers()) do -- Play Solo support
    if player.Character then
        player.Character:Destroy()
    end

    playerAdded(player)
end
0
Please put the entire script in the code lines Brinceous 85 — 7y
0
How do i do that? Cavedudemann 2 — 7y
0
Okay I put the script in code lines Cavedudemann 2 — 7y
0
http://wiki.roblox.com/index.php?title=API:Class/Player/LoadCharacter Try that instead of your loadChar function. GoldenPhysics 474 — 7y
View all comments (6 more)
0
Didn't work, don't know if I added it wrong or something. Gives me an error in output "eof expected, got "end"" in line 38, which is line 36 in the script above. Have no idea why i got this error. Cavedudemann 2 — 7y
0
Also, my custom character didn't show up at all when I used the load character function for some reason. Sorry, i'm a pretty new coder, so I'm not too good at it yet. Cavedudemann 2 — 7y
0
Problem is about the morph probably. Maybe anchored, maybe not connected w/ 6D Motor etc. superalp1111 662 — 7y
0
Thanks, my morphs are no longer stuck, and the dummy works perfectly fine, but my custom model still dies instantly and falls into the water. Not sure what would cause this, but I will have to do some close comparisons of morphs and stuff. Thanks again. Cavedudemann 2 — 7y
0
If CharacterAutoLoads is false, why do you have to check for an existing character? User#13152 0 — 7y
0
I'm actually not sure, but when that function is not added and you press play, you don't spawn, and you are left with just floating around like in studio mode. Cavedudemann 2 — 7y

Answer this question