IM ABOUT TO CRASH OUT. HELP.

https://preview.redd.it/yvtmia7c4mae1.png?width=741&format=png&auto=webp&s=3b63d2333b52d130d6e872b25f6fc6144c6f9398

HOW DO YOU FIX THIS?? I HAVE BEEN TRYING FOR 2 HOURS. I'm trying to make it so that when you load in your movement is set to 0 and you become invisible. Here's the code:

local function freezePlayer(character)

local humanoid = character:WaitForChild("Humanoid", 5)

local rootPart = character:WaitForChild("HumanoidRootPart", 5)

if not humanoid then

warn("Humanoid not found for character: " .. character.Name)

return

end

if not rootPart then

warn("HumanoidRootPart not found for character: " .. character.Name)

return

end

for _, part in pairs(character:GetDescendants()) do

if part:IsA("BasePart") then

part.Transparency = 1

part.CanCollide = false

end

end

humanoid.WalkSpeed = 0

humanoid.JumpPower = 0

humanoid.PlatformStand = true

rootPart.Anchored = true

print("Character frozen and made invisible:", character.Name)

end

game.Players.PlayerAdded:Connect(function(player)

player.CharacterAdded:Connect(function(character)

freezePlayer(character)

end)

if player.Character then

freezePlayer(player.Character)

end

end)