I have a tool.
This is structure:
This is code of Server Script:
01 | -- Server Script |
02 | local Tool = script.Parent |
03 | local clickEvent = Tool.Activated |
04 | local clickEventConnection |
05 |
06 | local function createPart(location) |
07 | local part = Instance.new( "Part" ) |
08 | part.CFrame = location |
09 | part.Parent = workspace |
10 | end |
11 |
12 | local function onClick(player, clickLocation) |
13 | wait( 0.5 ) |
14 | createPart(_G.PartSpawnToolLoc) |
15 | print (_G.PartSpawnToolLoc) |
16 | end |
17 |
18 | Tool.Activated:connect(onClick) |
This is code of Local Script:
01 | -- Local Script |
02 | local Tool = script.Parent |
03 | local player = game.Players.LocalPlayer |
04 | local mouse = player:GetMouse() |
05 |
06 | Tool.Equipped:Connect( function (Mouse) |
07 | Mouse.Button 1 Down:Connect( function () |
08 | _G.PartSpawnToolLoc = mouse.Hit |
09 | end ) |
10 | 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?
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.