#Character is not reloading after died

1 messages · Page 1 of 1 (latest)

heady tide
#

help. pls. you fall off and thats it

#

local reps = game:GetService("ReplicatedStorage")
local datast = game:GetService("DataStoreService")
local trolls = datast:GetDataStore("trolls")

-- Check if the rig exists before continuing

game.Players.PlayerAdded:Connect(function(player)

print("Changing character for:", player.Name)
local playertrolls = trolls:GetAsync(player.UserId)
print(playertrolls["slot0"])
local a = playertrolls["slot0"]
local rig = reps[a].Rig

if not rig then
    warn("Troll rig not found in ReplicatedStorage!")
    return
end

local height = reps[a].Height.Value
local speed = reps[a].Speed.Value



player.CharacterAdded:Wait()

local oldchar = player.Character
local newchar = rig:Clone()

newchar.Name = player.Name

player.Character = newchar
newchar.Parent = workspace
local newhum = newchar.Humanoid
local hum = oldchar.Humanoid

hum.Parent = newchar


hum.HipHeight = height
hum.WalkSpeed = speed
newhum:Destroy()

if oldchar then
    
    oldchar:Destroy()
    player.Character = newchar
    
end
#

robloxes ai only added "-- Check if the rig exists before continuing" to code

#

and nothing changed

void gorge
#

I think you need to detect when the player dies like this:
hum.Died:Connect(function()
task.wait(1)
player:LoadCharacterAsync()
-- then change character again once the character loads
end)

heady tide
#

its on another script lemme find

#

i thought my code was wrong

#

so i found example code from studio itself

heady tide
# void gorge I think you need to detect when the player dies like this: hum.Died:Connect(func...

local Players = game:GetService("Players")

local RESPAWN_DELAY = 5

Players.CharacterAutoLoads = false

local function onPlayerAdded(player)
local function onCharacterAdded(character)
local humanoid = character:WaitForChild("Humanoid")

    local function onDied()
        task.wait(RESPAWN_DELAY)
        player:LoadCharacter()
    end

    humanoid.Died:Connect(onDied)
end

player.CharacterAdded:Connect(onCharacterAdded)

player:LoadCharacter()

end

Players.PlayerAdded:Connect(onPlayerAdded)

void gorge
heady tide
#

yes

void gorge
#

idk this is what i did

#

I think you need to add an attribute to the custom character so it doesnt fire characterAdded again

heady tide
#

where is your script?

#

mine is in script service

void gorge
#

ServerScriptService

heady tide
#

ah

#

lemme try thx

heady tide
#

i think its need to be in same script

#

it worked like that thx

void gorge
#

oh ok