oh righht one sec charssssssssss
fixed full edited and fixed now try
It doesn’t show on the screenshot, but on the fourth line, ServerStorage is underlined.
make it game.ServerStorage charsssss
When I test it on roblox studio, it does nothing.
I just noticed @xperninshini changed the if statement. The condition in his if statement will never be true. The not operator first converts the name of char to false and after that, false is compared to “customchar”. And false is never equal to “customchar”. I have made this same name comparing mistake before. I’d recommend you to try my if statement.
Try putting a print statement within each if statement and see which if statements it gets to.
All of the current responses (except for the print to debug one) are wrong.
local fakeChar = game.ServerStorage['CharacterName'] -- The character to load, put it in ServerStorage
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.UserId == 0 then --replace 0 with your friends UserID
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
elseif player.UserId ~= 0 then -- Replace 0 with your friends userid
player:LoadCharacter()
end
end
function loadChar(player)
local char = fakeChar: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
playerAdded(player)
end -- Credits to DaMrNelson for most of the script.
That is a script with comment lines for you on where to replace them with your values/data.
Make sure to put your custom character into ServerStorage and make sure that your character has the following 2 scripts/instances inside.
If you still need help, please PM me on the devforum.
I agree. To fix it, I would change the
if not char.Name == "customchar" then
to
if char.Name ~= "customchar" then
That could work, but if @3vnp wanted to change the name of the character to the name of their friend, my if condition would work better. However, the code posted by @Sudden_Demise might be a better solution than my code would be even with the syntax fixes. My solution might be hacky and cause problems in other systems in the game, because there’s some extra character added firing.
Name the character StarterCharacter and put it in game.StarterPlayer
oh. I will see if I can do that.
This is sure to help!
@Sudden_Demise already posted a way to solve the problem using loadcharacter and I believe it will work. (Well, it uses loadcharacter for other players and a custom character loading function for the spesific player.)
wait a second.
Thank you so much! It works.
I noticed that your code only respawns the player with the custom character. For others, it loads character only once. I made some edits (All of the edits weren’t related to that.). If you want to know why I didn’t use Humanoid.Died:Wait(), see this
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local FAKE_CHAR = ServerStorage['CharName'] -- The character to load, put it in ServerStorage
local RESPAWN_TIME = 2.5 -- How many seconds the player remains dead before they respawn
local ID = 0 --replace 0 with your friends UserID
local diedConns = {}
Players.CharacterAutoLoads = false -- Disable default character loading
local function diedOrLeft(plr, charLoadFunct)
diedConns[plr]:Disconnect()
diedConns[plr] = nil
if charLoadFunct then
wait(RESPAWN_TIME)
charLoadFunct(plr)
end
end
local function loadCustomChar(plr)
local char = FAKE_CHAR:Clone()
char.Name = plr.Name
plr.Character = char
char.Parent = game.Workspace
diedConns[plr] = char.Humanoid.Died:Connect(function()
diedOrLeft(plr, loadCustomChar)
end)
end
local function loadChar(plr)
plr:LoadCharacter()
diedConns[plr] = plr.Character.Humanoid.Died:Connect(function()
diedOrLeft(plr, loadChar)
end)
end
local function playerAdded(plr)
if plr.UserId == ID then
loadCustomChar(plr)
else loadChar(plr)
end
end
game.Players.PlayerAdded:connect(playerAdded)
for i, player in pairs(game.Players:GetPlayers()) do
playerAdded(player)
end
Players.PlayerRemoving:Connect(diedOrLeft)
If you didn’t know, you can have multiple friends as once by doing this:
local id = "0", "1", "2", "3"
Just keep adding ,"0" 's at the end of every one.
Yeah, I posted it and didn’t look at the post. I feel like that Sudden_Demise’s method is the best method, now I’ve read it.