Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I set Character's Parent not workspace?

I found that the character is not respawning whiile I did set CharacterAutoLoad to true and did not do anything about Character's death. There is only script that changes the character's Parent

local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function (plr)
	plr.CharacterAdded:Connect(function (chr)
		chr = chr or plr.CharacterAdded:Wait()
		chr:WaitForChild("HumanoidRootPart")
		chr.Parent = workspace.Folder
		print(chr.Parent)
		while true do
			print (chr.Parent)
			wait(1)
		end
	end)
end)

outputs are like :

Folder

Folfder

Workspace

Workspace ...........Workspace

How can I assign character's Parent correctly not using wait(1) then Parent it to other?

2 answers

✓ Accepted answer

The problem is because when the character dies, the game will automatically reset the player's character into workspace instead of the folder. One way to fix this is to add a function to check for the player character's humanoid state so that when it dies, you can add a wait() function to wait for the character to spawn then add the character to the folder after.

You may refer to the following:

https://developer.roblox.com/en-us/api-reference/enum/HumanoidStateType

1 comment

0

Isn't CharacterAdded:() already waits for the character to spawn? Im confused. If it fires before the character spawns,I will try that way

First, make a remote event in replicated storage

and then #try this

-- script
local RemoteEvent = game.ReplicatedStorage:WaitForChild("RemoteEvent")

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(chr)
		wait()
		chr.Parent = workspace:WaitForChild("Folder")
		RemoteEvent:FireClient(plr)
	end)
end)

-- local script
local RemoteEvent = game.ReplicatedStorage:WaitForChild("RemoteEvent")

RemoteEvent.OnClientEvent:Connect(function()
	workspace.CurrentCamera.CameraSubject = game.Players.localplayer.Character:WaitForChild("HumanoidrootPart")
end)

if it still doesn't work, dm me at

Blue Duck#8344

This discussion is preserved as it was. New answers, comments, and votes are closed.