Teleports fail upon player death?

i have a LocalScript placed inside of a gui. this gui is placed inside of StarterGui. it works, but after my character dies once, the teleport zones stop functioning completely. i don’t know why.

this is my script, and quite frankly, i’m thoroughly stumped.

-- services
local tween_service = game:GetService("TweenService")
local replicated_storage = game:GetService("ReplicatedStorage")
local collection_service = game:GetService("CollectionService")
local user_input = game:GetService("UserInputService")
local player_service = game:GetService("Players")
local sound_service = game:GetService("SoundService")
local lighting = game:GetService("Lighting")

-- other stuff
local daytime_tag, nighttime_tag = "daytime", "nighttime"
local clocktime_day, clocktime_night = 14.5, 5.7

local client = player_service.LocalPlayer
local screen_gui = script.Parent
local starter_gui = screen_gui.Parent

local char = client.Character or client.CharacterAdded:Wait()
local root = char:WaitForChild("HumanoidRootPart")
local personoid = char:FindFirstChildWhichIsA("Humanoid")

-- modules
local zone_plus = require(replicated_storage:WaitForChild("Zone"))
local client_control = require(replicated_storage:WaitForChild("client_controller"))
local debounce = false

local function pivot_callback(obj)
	local char = client.Character or client.CharacterAdded:Wait()
	local root = char:WaitForChild("HumanoidRootPart")
	local personoid = char:FindFirstChildWhichIsA("Humanoid")
	
	if root and root:IsA("BasePart") then
		root:PivotTo(obj.CFrame)
	end
end

function woosh(callback, obj)
	if debounce then return end
	debounce = true
	sound_service:PlayLocalSound(sound_service:WaitForChild("sfx").ascend)
	
	local frame = screen_gui:WaitForChild("Frame")
	local frame_info = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
	
	task.spawn(function()
		local tween = tween_service:Create(frame, frame_info, {Position = UDim2.new(0.5,0,-3,0)})
		local color_correction = lighting:WaitForChild("unseeable")
		tween:Play()

		task.delay(0.4, function()
			color_correction.Enabled = true
			tween:Pause()
			
			task.wait(0.5)
			tween:Play()
			task.wait(0.07)
			color_correction.Enabled = false
			
			if callback then
				callback(obj)
			end
		end)
		
		tween.Completed:Connect(function()
			frame.Position = UDim2.new(0.5,0,3,0)
		end)
	end)
	
	task.wait(1.5)
	debounce = false
end

local function tween_time(clock_time)
	if lighting.ClockTime == clock_time then 
		print(`creature of steel`)
		return 
	end
	
	local lighting_info = TweenInfo.new(1, Enum.EasingStyle.Circular, Enum.EasingDirection.Out)
	local tween = tween_service:Create(lighting, lighting_info, {ClockTime = clock_time}):Play()
end

local zones = {
	workspace:WaitForChild("outer"),
	workspace:WaitForChild("flesh & bones"),
}

local function reset_zones()
	for _, container in ipairs(zones) do
		print(container)
		local zone = zone_plus.new(container)

		zone.playerEntered:Connect(function(player)
			if collection_service:HasTag(container, daytime_tag) then
				if personoid and personoid.Health ~= 0 then	
					task.spawn(function()
						tween_time(clocktime_day)
						client_control:cease()
					end)

					woosh(pivot_callback, container.associated_teleporter.Value)
				end
			elseif collection_service:HasTag(container, nighttime_tag) then
				if personoid and personoid.Health ~= 0 then
					task.spawn(function()
						tween_time(clocktime_night)
						client_control:initialize()
					end)

					woosh(pivot_callback, container.associated_teleporter.Value)
				end
			end
		end)
	end
end

reset_zones()

personoid.Died:Connect(function()
	reset_zones()
	
	task.spawn(function()
		tween_time(clocktime_day)
		client_control:cease()
	end)
end)

Does the StarterGui have “ResetOnSpawn” enabled? If so, disable it and see if this works.

1 Like

disabling it didn’t work.

[ character limit, ignore ]

i have decided to scrap the teleports as they were too much of a hassle.

I haven’t looked at this too much, so this could be wrong, but you might need to reset the character object as it is redefine the character variable whenever the player dies since it resets their character.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.