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

How can I set Character's Parent not workspace?

Asked by 2 years ago

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

Log in to vote
1
Answered by 2 years ago
Edited 2 years ago

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

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 TerranRecon 49 — 2y
Ad
Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

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

Answer this question