Issues with spawning and dying transition (FIXED)

I want to create a transition effect for my game. I’ve written most code alone, be aware I have used AI a bit to debug as I’m not the best on the topic of debugging, I hope you can understand. This is my error:

  00:15:54.277  Unable to create an Instance of type "AspectRatioConstraint"  -  Studio
  00:15:54.277  Stack Begin  -  Studio
  00:15:54.277  Script 'Players.maroclaww.PlayerGui.ScreenGui.LocalScript', Line 33 - function resetGui  -  Studio
  00:15:54.277  Script 'Players.maroclaww.PlayerGui.ScreenGui.LocalScript', Line 118  -  Studio
  00:15:54.277  Stack End  -  Studio
local player = game.Players.LocalPlayer
local playerGui = player.PlayerGui
local transitionImage = script.Parent:WaitForChild("TransitionImage")
local leftBar = script.Parent:WaitForChild("LeftBar")
local rightBar = script.Parent:WaitForChild("RightBar")
local tweenService = game:GetService("TweenService")

local remote = game.ReplicatedStorage:WaitForChild("Transition")

-- Function to play spawn transition
local function spawnTransition()
	-- Wait for any initial setup to be done if needed
	wait(1)  -- Wait for the GUI to be properly initialized (if necessary)

	-- Debugging output for spawn transition
	print("Executing spawn transition")

	-- Ensure the spawn sound exists and play it
	local spawnSound = script.Parent:FindFirstChild("Spawn")
	if spawnSound then
		spawnSound:Play()
	else
		print("Spawn sound not found!")
	end

	-- Animate bar movement (move the bars out of the screen)
	local barTweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
	local leftBarGoal = {Position = UDim2.new(-0.5, 0, 0, 0), Size = UDim2.new(0.5, 0, 1, 0)}
	local rightBarGoal = {Position = UDim2.new(1.5, 0, 0, 0), Size = UDim2.new(0.5, 0, 1, 0)}

	local leftTween = tweenService:Create(leftBar, barTweenInfo, leftBarGoal)
	local rightTween = tweenService:Create(rightBar, barTweenInfo, rightBarGoal)
	leftTween:Play()
	rightTween:Play()

	-- Animate the transition image to hide it
	local imageTweenInfo = TweenInfo.new(1, Enum.EasingStyle.Back, Enum.EasingDirection.Out)
	local imageTweenGoal = {Size = UDim2.new(0, 0, 0, 0), Position = UDim2.new(0.5, -146, 0.5, -146)}  -- Hide it
	local imageTween = tweenService:Create(transitionImage, imageTweenInfo, imageTweenGoal)
	imageTween:Play()

	-- Wait for the tweens to complete before moving forward
	leftTween.Completed:Wait()
	rightTween.Completed:Wait()
	imageTween.Completed:Wait()
end

-- Function to play death transition
local function deathTransition()
	-- Debugging output for death transition
	print("Executing death transition")

	-- Play death sound if it exists
	local deadSound = script.Parent:FindFirstChild("Dead")
	if deadSound then
		deadSound:Play()
	else
		print("Dead sound not found!")
	end

	-- Animate the bars to move back to the center of the screen
	local barTweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
	local leftBarGoal = {Position = UDim2.new(0, 0, 0, 0), Size = UDim2.new(0.5, 0, 1, 0)}
	local rightBarGoal = {Position = UDim2.new(0.5, 0, 0, 0), Size = UDim2.new(0.5, 0, 1, 0)}

	local leftTween = tweenService:Create(leftBar, barTweenInfo, leftBarGoal)
	local rightTween = tweenService:Create(rightBar, barTweenInfo, rightBarGoal)
	leftTween:Play()
	rightTween:Play()

	-- Animate the transition image to appear (bring it back to center)
	local imageTweenInfo = TweenInfo.new(1, Enum.EasingStyle.Back, Enum.EasingDirection.In)
	local imageTweenGoal = {Size = UDim2.new(0, 293, 0, 293), Position = UDim2.new(0.5, -146, 0.5, -146)}  -- Center it
	local imageTween = tweenService:Create(transitionImage, imageTweenInfo, imageTweenGoal)
	imageTween:Play()

	-- Wait for the tweens to complete
	leftTween.Completed:Wait()
	rightTween.Completed:Wait()
	imageTween.Completed:Wait()
end

-- Listen for remote event to trigger spawn or death transitions
remote.OnClientEvent:Connect(function(action)
	print("Received action: " .. action)  -- Debugging output

	if action == "spawn" then
		spawnTransition()  -- Just handle the spawn transition
	elseif action == "death" then
		deathTransition()  -- Just handle the death transition
	end
end)

above was my client script
below is my server script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local transitionRemote = ReplicatedStorage:WaitForChild("Transition")

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		-- Check if the GUI already exists and reset it if needed
		local existingGui = player.PlayerGui:FindFirstChild("ScreenGui")
		if existingGui then
			existingGui:Destroy()
		end

		-- Clone the GUI from the template in the script
		local gui = script.ScreenGui:Clone()
		gui.Parent = player.PlayerGui
		gui.Enabled = true

		-- Apply Aspect Ratio Constraint to the entire ScreenGui
		local aspectRatioConstraint = Instance.new("UIAspectRatioConstraint")
		aspectRatioConstraint.Parent = gui 
		aspectRatioConstraint.AspectRatio = 1.7778 -- 16:9 aspect ratio

		-- Trigger spawn transition
		print("Firing spawn transition for " .. player.Name)
		transitionRemote:FireClient(player, "spawn")

		-- Handle player death
		local humanoid = character:WaitForChild("Humanoid")
		humanoid.Died:Connect(function()
			print("Firing death transition for " .. player.Name)
			transitionRemote:FireClient(player, "death")
		end)
	end)
end)

adssd
asdsds

As implied earlier, I’m not the sharpest tool in the shed, and help could go a very, very long way.

1 Like

bumping my own post because i have gotten no response in the last 30 minutes

2 Likes

Do you get anything in your output? If so can I see it?

Also your reply above is the most realest thing. :rofl:

1 Like

I would suggest creating the UI on the client side, rather than the server.

server fires remote event to client
client creates appropriate UI
client does normal actions

server fires remtoe event to client to destroy/edit
client does actions

That’s what I’m doing? I thought I showed which scripts are client and server-sided.

And it isn’t “making” the ui. I have the UI, the remote event is meant to fire and do the tranisition. Before I had this error too, the UI randomly broke when respawning. The script didn’t respond and the only thing doing anything is the server script, which calls for the spawn transition with no response.

I fixed the GUI! How am i meant to make this the minimum characters?

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