Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Camera won't go to player position after respawn?

Hello! I created a team change gui, and basically when you spawn in your camera is at a certain parts CFrame. If a team is chosen, then your player respawns and the camera goes back to your player after it dies. However, when I chose to be on the "Infants" team, the camera goes back to player but it is stuck in position, I found out it works after you reset though. The camera works fine when the "Adults" team is chosen.

The problem has to do with line 79, but I'll post the whole script so there isn't any confusion. Thank you for reading!

local core = script.Parent.Parent.Core

local player = game:GetService('Players').LocalPlayer
local character = player.Character or player.CharacterAdded:wait()
local HumanoidRootPart = character:WaitForChild('HumanoidRootPart')

local Camera = game.Workspace.CurrentCamera

local BLUR = game.Lighting.Blur


local RemoteEvent = game.ReplicatedStorage.Remotes.ChangeTeam

local menuButton

local InfantBTN = script.Parent:WaitForChild("Infant"):WaitForChild("Button")

local ParentBTN = script.Parent:WaitForChild("Adult"):WaitForChild("Button")

local GUI = script.Parent

local TweenService = game:GetService("TweenService")

local InfantColor = "Cool yellow"

local ParentColor = "Persimmon"


InfantBTN.MouseButton1Click:Connect(function()

-- Tween the button
local tweenInfo = TweenInfo.new(.1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, true, 0)

local goal = {}
goal.Position = (UDim2.new(0.048, 0,0.387, 0))
goal.Size = (UDim2.new(0, 213,0, 165))

local tween = TweenService:Create(InfantBTN, tweenInfo, goal)

tween:Play()

	-- Fire the Remote Event
	RemoteEvent:FireServer(BrickColor.new(InfantColor))
	wait(.5)
	GUI.Enabled = false

BLUR.Size = 1.1

Camera.CameraType = "Custom"

Camera.CFrame = HumanoidRootPart.CFrame

core.Enabled = true

end)

ParentBTN.MouseButton1Click:Connect(function()

-- Tween the button
local tweenInfo = TweenInfo.new(.1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, true, 0)

local goal = {}
goal.Position = (UDim2.new(0.048, 0,0.387, 0))
goal.Size = (UDim2.new(0, 213,0, 165))

local tween = TweenService:Create(ParentBTN, tweenInfo, goal)

tween:Play()

	-- Fire the Remote Event
	RemoteEvent:FireServer(BrickColor.new(ParentColor))
	wait(.5)
	GUI.Enabled = false

BLUR.Size = 1.1

Camera.CameraType = "Custom"

Camera.CFrame = HumanoidRootPart.CFrame

core.Enabled = true

end)

1 answer

✓ Accepted answer

The problem here is that the character changes after you respawn, so the reference that you kept of the HumanoidRootPart is of the old dead character, and not the new character. The way that you would fix this is getting the player's character each time they click ParentBTN, and using that reference's HumanoidRootPart.

1 comment

0

Thank you!! :) I will keep this in mind for the future.

This discussion is preserved as it was. New answers, comments, and votes are closed.