Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 1 year ago

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)



0
does the script itself not work or it's morphing you but shows the error sometimes imKirda 4491 — 1y
0
if it works and the error bothers you you should do if Root then to check if the HumanoidRootPart exists imKirda 4491 — 1y
0
It doesn't work. esmith68789 9 — 1y
0
It doesn't morph me, it just sends an error. esmith68789 9 — 1y
0
oh im blind change plr:FindFirstChild to character:FindFirstChild, plr is the one in Players, character is the one in Workspace imKirda 4491 — 1y

1 answer

Log in to vote
0
Answered by
OhManXDXD 445 Moderation Voter
1 year ago

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)
Ad

Answer this question