To keep it simple, I am making a script that makes it so the player respawns to a specific part when they die after they trigger a proximity prompt.
The script should work fine, and it prints out the statements I have.
My problem comes at the teleportation logic. For some reason, it doesn’t teleport the player to the specified part.
This is strange, because I used the same teleportation logic in a different script and it works.
Here is my script (it is inside the part that has the proximity prompt):
local RespawnPart = game.Workspace.StageSpawnPoints.Cloud.Stage1Spawn
local SpawnSetPart = game.Workspace.Stages.Cloud.Stage1.Portal.SpawnSetPart
local proxtrig = false
local Players = game:GetService("Players")
SpawnSetPart.ProximityPrompt.Triggered:Connect(function()
proxtrig = true
end)
local function onPlayerAdded(player)
local function onCharacterAdded(character)
local humanoid = character:WaitForChild("Humanoid")
humanoid.Died:Connect(function()
if proxtrig == true then
print("true")
wait(5)
local humanoidRootPart = character and character:FindFirstChild("HumanoidRootPart")
if humanoidRootPart then
humanoidRootPart.CFrame = CFrame.new(RespawnPart.Position)
print("should work")
end
else
print("proxtrig false")
end
end)
end
player.CharacterAdded:Connect(onCharacterAdded)
end
Players.PlayerAdded:Connect(onPlayerAdded)