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
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.
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)
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)