Attempt to index nil with name from instance

local Mouse = game.Players.LocalPlayer:GetMouse()
local Positiona = nil
local Rot = Vector3.new(0, -90, 0)
local UIS = game:GetService("UserInputService")
local ObjToSpawn = nil
local The = script.Parent:WaitForChild("Object")

UIS.InputBegan:Connect(function(Key)
	if Key.KeyCode == Enum.KeyCode.R then
		Rot += Vector3.new(0, -90, 0)
		
		if script.Parent:FindFirstChild("Ghost") then
			script.Parent.Ghost:Destroy()
		end
		if ObjToSpawn.Name ~= nil then
			local Ghost = ObjToSpawn:Clone()
			Ghost.Parent = script.Parent
			Ghost.Name = "Ghost"
			Ghost:SetPrimaryPartCFrame(Positiona)
			Ghost:PivotTo(Positiona * CFrame.Angles(math.rad(Rot.X),math.rad(Rot.Y + 90),math.rad(Rot.Z)))
			for _, V in pairs(ObjToSpawn:GetChildren()) do
				if V:IsA("BasePart") then
					V.Transparency = 0.8
					V.Color = Color3.new(0, 0, 0)
				end
			end
		end

	end
end)

script.Parent.Activated:Connect(function()
	
	script.Parent.place:FireServer(Positiona, Rot)
	
end)

The.OnClientEvent:Connect(function(plrr, object)
	print("stating"..object.Name)
	if plrr == game.Players.LocalPlayer.Name then
		print(object.Name)
		ObjToSpawn = object
		if script.Parent:FindFirstChild("Ghost") then
			script.Parent.Ghost:Destroy()
		end
	end
end)

Mouse.Move:Connect(function()
	local GridSize = nil
	print(typeof(ObjToSpawn))
	if ObjToSpawn.Name == "Wire" then
		GridSize = 1
		print("gridsize1")
	else
		GridSize = 4
		print("gridsize4")
	end
	local X = math.floor((Mouse.Hit.X + GridSize / 2) / GridSize) * GridSize
	local Y = math.ceil((Mouse.Hit.Y + GridSize / 4 ) / GridSize) * GridSize - 3.85
	local Z = math.floor((Mouse.Hit.Z + GridSize / 2) / GridSize) * GridSize
	Positiona = CFrame.new(X, Y, Z)
	
	if script.Parent:FindFirstChild("Ghost") then
		script.Parent.Ghost:Destroy()
	end
	
	if ObjToSpawn ~= nil then
		local Ghost = ObjToSpawn:Clone()
		Ghost.Parent = script.Parent
		Ghost.Name = "Ghost"
		Ghost:SetPrimaryPartCFrame(Positiona)
		Ghost:PivotTo(Positiona * CFrame.Angles(math.rad(Rot.X),math.rad(Rot.Y + 90),math.rad(Rot.Z)))
		for _, V in pairs(ObjToSpawn:GetChildren()) do
			if V:IsA("BasePart") then
				V.Transparency = 0.8
				V.Color = Color3.new(0, 0, 0)
			end
		end
	end

end)

when doing objecttospawn.name it says attempt to index nil with name
objecttospawn is an instance, so idk why its doing this

ObjToSpawn is initialized as nil and not any kind of Instance.
Maybe initialize ObjToSpawn to an Instance.

ik that wont work because even after its turned into an instance it still give the error. and i print it out to make sure its

  1. an instance
  2. not nil
  3. its the proper istance
local Mouse = game.Players.LocalPlayer:GetMouse()
local Positiona = nil
local Rot = Vector3.new(0, -90, 0)
local UIS = game:GetService("UserInputService")
local ObjToSpawn = nil
local The = script.Parent:WaitForChild("Object")

UIS.InputBegan:Connect(function(Key)
	if Key.KeyCode == Enum.KeyCode.R then
		Rot += Vector3.new(0, -90, 0)
		
		if script.Parent:FindFirstChild("Ghost") then
			script.Parent.Ghost:Destroy()
		end
		if ObjToSpawn ~= nil then
			local Ghost = ObjToSpawn:Clone()
			Ghost.Parent = script.Parent
			Ghost.Name = "Ghost"
			Ghost:SetPrimaryPartCFrame(Positiona)
			Ghost:PivotTo(Positiona * CFrame.Angles(math.rad(Rot.X),math.rad(Rot.Y + 90),math.rad(Rot.Z)))
			for _, V in pairs(ObjToSpawn:GetChildren()) do
				if V:IsA("BasePart") then
					V.Transparency = 0.8
					V.Color = Color3.new(0, 0, 0)
				end
			end
		end

	end
end)

script.Parent.Activated:Connect(function()
	
	script.Parent.place:FireServer(Positiona, Rot)
	
end)

The.OnClientEvent:Connect(function(plrr, object)
	print("stating"..object.Name)
	if plrr == game.Players.LocalPlayer.Name then
		print(object.Name)
		ObjToSpawn = object
		if script.Parent:FindFirstChild("Ghost") then
			script.Parent.Ghost:Destroy()
		end
	end
end)

Mouse.Move:Connect(function()
	local GridSize = nil
	print(typeof(ObjToSpawn))
	if ObjToSpawn.Name == "Wire" then
		GridSize = 1
		print("gridsize1")
	else
		GridSize = 4
		print("gridsize4")
	end
	local X = math.floor((Mouse.Hit.X + GridSize / 2) / GridSize) * GridSize
	local Y = math.ceil((Mouse.Hit.Y + GridSize / 4 ) / GridSize) * GridSize - 3.85
	local Z = math.floor((Mouse.Hit.Z + GridSize / 2) / GridSize) * GridSize
	Positiona = CFrame.new(X, Y, Z)
	
	if script.Parent:FindFirstChild("Ghost") then
		script.Parent.Ghost:Destroy()
	end
	
	if ObjToSpawn ~= nil then
		local Ghost = ObjToSpawn:Clone()
		Ghost.Parent = script.Parent
		Ghost.Name = "Ghost"
		Ghost:SetPrimaryPartCFrame(Positiona)
		Ghost:PivotTo(Positiona * CFrame.Angles(math.rad(Rot.X),math.rad(Rot.Y + 90),math.rad(Rot.Z)))
		for _, V in pairs(ObjToSpawn:GetChildren()) do
			if V:IsA("BasePart") then
				V.Transparency = 0.8
				V.Color = Color3.new(0, 0, 0)
			end
		end
	end

end)

is this an updated version of the script?

Try using:

if not instance then
    return print(instance)
end

Since it might not be still not initialized into an Instance.

Yeah, you did

If Instance.Name ~= nil then

Instead of

If Instance ~= nil then

might be the problem

i tried it, it works kinda, its jsut that the wire doent show up when i choose to place that

Maybe this will work? I saw that the way you’re making the ghost block move is by destroying and adding it back everytime the mouse moves… so, that might be the problem…

local Mouse = game.Players.LocalPlayer:GetMouse()
local Positiona = nil
local Rot = Vector3.new(0, -90, 0)
local UIS = game:GetService("UserInputService")
local ObjToSpawn = nil
local The = script.Parent:WaitForChild("Object")
local Ghost

UIS.InputBegan:Connect(function(Key)
	if Key.KeyCode == Enum.KeyCode.R then
		Rot += Vector3.new(0, -90, 0)
		
		if ObjToSpawn ~= nil then
			
			if Ghost == nil then
			    Ghost = ObjToSpawn:Clone()
			    Ghost.Name = "Ghost" .. ObjToSpawn.Name
			elseif Ghost ~= nil and "Ghost" .. ObjToSpawn.Name ~= Ghost.Name then
			    Ghost:Destroy()
			    Ghost = ObjToSpawn:Clone()
                Ghost.Name = "Ghost" .. ObjToSpawn.Name
			end
			
			if Ghost ~= nil then
			    Ghost.Parent = script.Parent
			    Ghost:SetPrimaryPartCFrame(Positiona)
		     	Ghost:PivotTo(Positiona * CFrame.Angles(math.rad(Rot.X),math.rad(Rot.Y + 90),math.rad(Rot.Z)))
			    for _, V in pairs(ObjToSpawn:GetChildren()) do
				   if V:IsA("BasePart") then
				    	V.Transparency = 0.8
				    	V.Color = Color3.new(0, 0, 0)
			    	end
		    	end
			end
		end

	end
end)

script.Parent.Activated:Connect(function()
	
	script.Parent.place:FireServer(Positiona, Rot)
	
end)

The.OnClientEvent:Connect(function(plrr, object)
	print("stating"..object.Name)
	if plrr == game.Players.LocalPlayer.Name then
		print(object.Name)
		ObjToSpawn = object
	end
end)

Mouse.Move:Connect(function()
	local GridSize = nil
	print(typeof(ObjToSpawn))
	if ObjToSpawn.Name == "Wire" then
		GridSize = 1
		print("gridsize1")
	else
		GridSize = 4
		print("gridsize4")
	end
	local X = math.floor((Mouse.Hit.X + GridSize / 2) / GridSize) * GridSize
	local Y = math.ceil((Mouse.Hit.Y + GridSize / 4 ) / GridSize) * GridSize - 3.85
	local Z = math.floor((Mouse.Hit.Z + GridSize / 2) / GridSize) * GridSize
	Positiona = CFrame.new(X, Y, Z)
	
		if ObjToSpawn ~= nil then
			
			if Ghost == nil then
			    Ghost = ObjToSpawn:Clone()
			    Ghost.Name = "Ghost" .. ObjToSpawn.Name
			elseif Ghost ~= nil and "Ghost" .. ObjToSpawn.Name ~= Ghost.Name then
			    Ghost:Destroy()
			    Ghost = ObjToSpawn:Clone()
                Ghost.Name = "Ghost" .. ObjToSpawn.Name
			end
			
			if Ghost ~= nil then
			    Ghost.Parent = script.Parent
			    Ghost:SetPrimaryPartCFrame(Positiona)
		     	Ghost:PivotTo(Positiona * CFrame.Angles(math.rad(Rot.X),math.rad(Rot.Y + 90),math.rad(Rot.Z)))
			    for _, V in pairs(ObjToSpawn:GetChildren()) do
				   if V:IsA("BasePart") then
				    	V.Transparency = 0.8
				    	V.Color = Color3.new(0, 0, 0)
			    	end
		    	end
			end
		end


end)

well i didnt want it to do that anyways, i am making a new “wiretool”, where when you hover over an object, it snaps the plug to the object… im having problems makign that work. can you help?

Yeah, i made something similiar (grid building system) before so i can help

basically this is the script:

local Mouse = game.Players.LocalPlayer:GetMouse()
local Positiona = nil
local Rot = Vector3.new(0, -90, 0)
local UIS = game:GetService("UserInputService")
local Sender = game.ReplicatedStorage:WaitForChild("HoverSendr")
local Wire = game.ReplicatedStorage:WaitForChild("GatesAndStuff"):WaitForChild("Wire")

Sender.OnClientEvent:Connect(function(object, Type)
	local Weld = Instance.new("Weld")
	Weld.Parent = object
	Weld.Part0 = object
	
	local wire = Wire:Clone()
	wire.Parent = script.Parent
	Weld.Part1 = wire.AttachPart
end)

Also another script just fires an event sending data that is
player, instance, type
(player) (Object path) (Input/Output port)

Are you trying to weld the wire to a object?

yes, actually, do you want access to the game and i can explain more in depth?

Sure if you want, but to weld stuff in place you can just use weldconstraint which automatically does it!

local Mouse = game.Players.LocalPlayer:GetMouse()
local Positiona = nil
local Rot = Vector3.new(0, -90, 0)
local UIS = game:GetService("UserInputService")
local Sender = game.ReplicatedStorage:WaitForChild("HoverSendr")
local Wire = game.ReplicatedStorage:WaitForChild("GatesAndStuff"):WaitForChild("Wire")

Sender.OnClientEvent:Connect(function(object, Type)
	local Weld = Instance.new("WeldConstraint")
	Weld.Parent = object
	Weld.Part0 = object
	
	local wire = Wire:Clone()
	wire.Parent = script.Parent
	Weld.Part1 = wire.AttachPart
end)

And you should be set, just change the Instance.new(“Weld”) to Instance.new(“WeldConstraint”)

oh sorry i know, ive made a welding system similar im jsut tired while scripting. add me as a friend and ill invite you

sent you a friend request
char lmit

Alrighty, done! I accepted your request

im adding u to the test hold on its loading
when i add you, go to startpack > wiretool > localscript
ill talk to u there

alright, got it!
charlimitaaaahh