Attempt to index nil with, hit

try this


local dummy = workspace.Dummy
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
print("established locals")

script.Parent.Activated:Connect(function()
	print("made func")
	mouse.Button1Down:Connect(function()
		print("recognized click")
		game.ReplicatedStorage.Spawner:FireServer(mouse.Hit) -- removed plr here
	end)
end)

--// Server script in ServerScriptService \\
local dummy = workspace.Dummy
game.ReplicatedStorage.Spawner.OnServerEvent:Connect(function(plr, oldmouse)
    local new = dummy:Clone()
	print("cloned")
	new.HumanoidRootPart.CFrame = oldmouse
--The error is on this line ^^^
end)
local dummy = workspace.Dummy
game.ReplicatedStorage.Spawner.OnServerEvent:Connect(function(plr, oldmouse)
	local new = dummy:Clone()
	print("cloned")
	new.HumanoidRootPart.CFrame = oldmouse
	print("tped")
end)

does work but where it sets the CFrame to old mouse it doesn’t work. The script just passes right through it without any error or anything and continues the rest of the script.

it printed both cloned and tped ?

yes. it went through the whole code without any errors but never tped the dummy

once try replacing dummy with a part and see if that works…

local dummy = -- part
game.ReplicatedStorage.Spawner.OnServerEvent:Connect(function(plr, oldmouse)
	local new = dummy:Clone()
	print("cloned")
	new.CFrame = oldmouse
	print("tped")
end)

same thing happens with the part

try this

local dummy = -- part
game.ReplicatedStorage.Spawner.OnServerEvent:Connect(function(plr, oldmouse)
	local new = dummy:Clone()
	print("cloned")
    new.Parent = game.Workspace
	new.CFrame = oldmouse
	print("tped")
end)
1 Like

worked! i don’t know why it wouldn’t already be in workspace though, but thanks!

Actually, try this it might be better:

local dummy = -- part
game.ReplicatedStorage.Spawner.OnServerEvent:Connect(function(plr, mouseX, mouseY, mouseZ)
	local new = dummy:Clone()
	print("cloned")
    new.Parent = game.Workspace
	new:SetPrimaryPartCFrame(cframe.new(mouseX, mouseY, mouseZ))
	print("tped")
end)

And at the client script do

:Fire(Mouse.X, Mouse.Y, Mouse.Z)

yea this might also work, but I guess both do the same work