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

Chat Command Morph | "UniformScript:14: attempt to index nil with 'CFrame'" ?

Hello! I have a script that is supposed to morph a player to ROBLOX package if they say a chat command, but I receive the error "UniformScript:14: attempt to index nil with 'CFrame'" Can anyone help?

My script:

local PlayerService = game:GetService("Players")
local ChatService = game:GetService("Chat")
local ServerStorage = game:GetService("ServerStorage")
local Morphs = ServerStorage.Morphs


PlayerService.PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function(msg)
		if msg == "-uniform" then
			if plr.leaderstats.XP.Value > 35000 and plr.leaderstats.XP.Value < 85000 then
				local character = plr.Character
				local Root = plr:FindFirstChild("HumanoidRootPart")
				local MorphCharacter = Morphs:FindFirstChild("Guard"):Clone()
				MorphCharacter.HumanoidRootPart.CFrame = Root.CFrame
				plr.Character = MorphCharacter
				character:Destroy()
				MorphCharacter.Parent = workspace
			end
			
		end
	end)
end)



5 comments

0

does the script itself not work or it's morphing you but shows the error sometimes

0

if it works and the error bothers you you should do if Root then to check if the HumanoidRootPart exists

0

It doesn't work.

0

It doesn't morph me, it just sends an error.

0

oh im blind change plr:FindFirstChild to character:FindFirstChild, plr is the one in Players, character is the one in Workspace

1 answer

✓ Accepted answer

You're looking for the HumanoidRootPart in the player, I think you meant to look for it in the player's Character.

local PlayerService = game:GetService("Players")
local ChatService = game:GetService("Chat")
local ServerStorage = game:GetService("ServerStorage")
local Morphs = ServerStorage.Morphs


PlayerService.PlayerAdded:Connect(function(plr)
    plr.Chatted:Connect(function(msg)
        if msg == "-uniform" then
            if plr.leaderstats.XP.Value > 35000 and plr.leaderstats.XP.Value < 85000 then
                local character = plr.Character
                local Root = character:FindFirstChild("HumanoidRootPart")
                local MorphCharacter = Morphs:FindFirstChild("Guard"):Clone()
                MorphCharacter.HumanoidRootPart.CFrame = Root.CFrame
                plr.Character = MorphCharacter
                character:Destroy()
                MorphCharacter.Parent = workspace
            end

        end
    end)
end)

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