Need help with teleporting player after boss is killed

Hello everyone!
I’m having trouble with teleporting the player or players after the boss is killed. What I want to happen is when the boss dies, the player(s) get teleported to a certain area. But when I kill the boss, I’m not teleported. Could someone please help me with this.
Here is my code which is a server script in the workspace:

local shadow = game.ServerStorage:WaitForChild("Shadows")
local stage2 = script.Parent.Stage2

local function teleport(part)
	local plrChar = part.Parent:FindFirstChild(part.Parent.Name)
	if shadow.Humanoid.Died or shadow.Humanoid.Health == 0 then
		print("Shadow Died")
		print("Teleporting...")
		plrChar.CFrame = stage2.CFrame + Vector3.new(0,5,0)
		print("Done")
	end
end

Thank you for any help

Also, there are no errors in the output

Since player character is a model you need to use:
playerCharacter:SetPrimaryPartCFrame(stage2.CFrame + Vector3.new(0,5,0))
replace “playerCharacter” with yours player character reference.

It didn’t work, just had the same mistake like before

How are you calling the function, also print part.

When shadow dies
charlimitssuck

Ok show that part, because there is no “part” parameter when shadow dies.

Wouldn’t this be the argument?

Change

local plrChar = part.Parent:FindFirstChild(part.Parent.Name)

To

local plrChar = part.Parent

And add a check if he is a player or not.

But how do you call the function? This is checking when shadow dies in the function.

Alright well I’m not gonna waste time anymore, this should be your script:

local shadow = game.ServerStorage:WaitForChild("Shadows")
local stage2 = script.Parent.Stage2
local Players = game:GetService("Players")

local function teleport()
	print("Shadow Died")
	print("Teleporting...")
    for _, player in pairs(Players:GetPlayers()) do
        local plrChar = player.Character or player.CharacterAdded:Wait()
		plrChar.CFrame = stage2.CFrame + Vector3.new(0,5,0)
    end
	print("Done")
end

shadow.Humanoid.Died:Connect(teleport)

The output errors and reads “CFrame is not a Valid member of Workspace.Dfn150”

Ok, here use this, forgot one word lol:


local shadow = game.ServerStorage:WaitForChild("Shadows")
local stage2 = script.Parent.Stage2
local Players = game:GetService("Players")

local function teleport()
	print("Shadow Died")
	print("Teleporting...")
    for _, player in pairs(Players:GetPlayers()) do
        local plrChar = player.Character or player.CharacterAdded:Wait()
		plrChar.HumanoidRootPart.CFrame = stage2.CFrame + Vector3.new(0,5,0)
    end
	print("Done")
end

shadow.Humanoid.Died:Connect(teleport)
1 Like

Add

shadow.Humanoid.Died:Connect(teleport)

This won’t work with his original script as there is no “part” parameter for that. He should use my script.

1 Like

@domboss37 code is fine but change

plrChar.CFrame = stage2.CFrame + Vector3.new(0,5,0)

To

plrChar:SetPrimaryPartCFrame(stage2.CFrame * CFrame.new(Vector3.new(0,5,0)))

Ah, I see. Nice job

Characters

Alright, thank you all for your help!