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

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

Asked by 5 years ago

I have a tool.

This is structure:

Screen

This is code of Server Script:

01-- Server Script
02local Tool = script.Parent
03local clickEvent = Tool.Activated
04local clickEventConnection
05 
06local function createPart(location)
07    local part = Instance.new("Part")
08    part.CFrame = location
09    part.Parent = workspace
10end
11 
12local function onClick(player, clickLocation)
13    wait(0.5)
14    createPart(_G.PartSpawnToolLoc)
15    print(_G.PartSpawnToolLoc)
16end
17 
18Tool.Activated:connect(onClick)

This is code of Local Script:

01-- Local Script
02local Tool = script.Parent
03local player = game.Players.LocalPlayer
04local mouse = player:GetMouse()
05 
06Tool.Equipped:Connect(function(Mouse)
07    Mouse.Button1Down:Connect(function()
08        _G.PartSpawnToolLoc = mouse.Hit
09    end)
10end)

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

Log in to vote
0
Answered by 5 years ago

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.

Ad

Answer this question