I have a tool.
This is structure:
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?
