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

Workspace.PartSpawnTool.Script:8: bad argument #3 to 'CFrame' (CFrame expected, got nil)?

I have a tool.

This is structure:

Screen

This is code of Server Script:

-- Server Script
local Tool = script.Parent
local clickEvent = Tool.Activated
local clickEventConnection

local function createPart(location)
	local part = Instance.new("Part")
	part.CFrame = location
	part.Parent = workspace
end

local function onClick(player, clickLocation)
	wait(0.5)
	createPart(_G.PartSpawnToolLoc)
	print(_G.PartSpawnToolLoc)
end

Tool.Activated:connect(onClick)

This is code of Local Script:

-- Local Script
local Tool = script.Parent
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

Tool.Equipped:Connect(function(Mouse)
	Mouse.Button1Down:Connect(function()
		_G.PartSpawnToolLoc = mouse.Hit
	end)
end)

When i click with tool it should to be create a part in the mouse location, but there is an error:

Workspace.PartSpawnTool.Script:8: bad argument #3 to 'CFrame' (CFrame expected, got nil)

Why it isn't work?

1 answer

I am just messing around with Scripting Helpers, I am new haha.

If you have not known this, the value is nil, that's mean you did not reference the variable properly. I think you should try using Remote Events, so you can bring the values over to the two scripts. Plus, it is safer for your game.

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