You can write your topic however you want, but you need to answer these questions:
- What do you want to achieve?
I would like to have a working character-choosing system as a randomizer
- What is the issue?
The issue is that when I reset my character or I die in-game, the camera breaks
Here’s a video:
robloxapp-20240119-1326515.wmv (1.7 MB)
- What solutions have you tried so far?
I’ve used AI to try to fix it, but it failed.
This is my script:
local Chances = require(script.Chances)
game.Players.PlayerAdded:Connect(function(plr)
local characterAddedConn
local characterRemovingConn
characterAddedConn = plr.CharacterAdded:Connect(function(char)
local Chosen = Chances.PickObject()
local Clone = game.ServerStorage.Characters:WaitForChild(Chosen.Name):Clone()
Clone.Name = plr.Name
local Rootp = Clone:FindFirstChild("HumanoidRootPart")
local Plrp = char:FindFirstChild("HumanoidRootPart")
if Rootp and Plrp then
Rootp.CFrame = Plrp.CFrame
end
char:Destroy()
Clone.Parent = workspace
for i, part in pairs(Clone:GetDescendants()) do
if part:IsA("BasePart") then
part.Anchored = false
end
end
plr.Character = Clone
-- Set HumanoidDescription for the chosen character
local humanoid = Clone:FindFirstChildOfClass("Humanoid")
if humanoid then
local humanoidDescription = Instance.new("HumanoidDescription",Clone)
humanoidDescription.HatAccessory = Chosen.HatAccessory
humanoidDescription.BodyTypeScale = Chosen.BodyTypeScale
humanoidDescription.ClimbAnimation = Chosen.ClimbAnimation
humanoidDescription.Face = Chosen.Face
humanoidDescription.GraphicTShirt = Chosen.GraphicTShirt
humanoidDescription.HeadColor = Chosen.HeadColor
humanoid:ApplyDescription(humanoidDescription)
end
-- Update camera position
local camera = workspace.CurrentCamera
while wait() do
camera.CameraSubject = Clone:FindFirstChildOfClass("Humanoid")
end
-- Disconnect the characterAddedConn and characterRemovingConn when the character is removed
characterRemovingConn = plr.CharacterRemoving:Connect(function()
characterAddedConn:Disconnect()
characterRemovingConn:Disconnect()
end)
end)
end)