Its probably something dumb but help me out

when I click the button that spawns the part in it says attempt to index nil with cframe what is wrong with this code.

local rs = game:GetService("ReplicatedStorage")
local remote = rs.RemoteEvent
local player = game:GetService("Players")


remote.OnServerEvent:Connect(function(player)
	local char = player.Character
	local hum = char:WaitForChild("Humanoid")
	local humrp = hum:FindFirstChild("HumanoidRootPart")
	local part = Instance.new("Part")
	part.Material = Enum.Material.Neon
	part.Color = Color3.fromRGB(129, 255, 240)
	part:Clone()
	part.Parent = workspace
	
	part.CFrame = humrp.CFrame + Vector3.new(3,3,3)
	part.Orientation = humrp.Orientation
	
	wait(3)
	part:Destroy()
	
end)
	
	
1 Like

I believe it’s just a typo. You declared the humrp variable as hum:FindFirstChild("HumanoidRootPart"). Obviously, HumanoidRootPart does not exist in your Humanoid, therefore it’s value is nil and does not return a CFrame

3 Likes

What do you mean there is no humanoid root part in my humanoid

1 Like

Yea you should replace it with this:

local humrp = char:FindFirstChild("HumanoidRootPart")
1 Like

I mean the Humanoid instance itself. You used FindFirstChild, meaning you attempted to find a part named “HumanoidRootPart” inside of a Humanoid instance.

1 Like

Also I think this topic would be better suited in Scripting Support.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.