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:

-- 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

Log in to vote
0
Answered by 4 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