I create a Tool following this tutorial: Player Tools
This is structure: Screen
This is code of Server Script:
-- Server Script local tool = script.Parent local clickEvent = tool.ClickEvent local clickEventConnection local function createPart(location) local part = Instance.new("Part") part.CFrame = location part.Parent = workspace end local function onClick(player, clickLocation) createPart(clickLocation) end local function onEquip() clickEventConnection = clickEvent.OnServerEvent:connect(onClick) end local function onUnequip() clickEventConnection:disconnect() end tool.Equipped:connect(onEquip) tool.Unequipped:connect(onUnequip)
This is code of Local Script:
-- Local Script local tool = script.Parent local player = game.Players.LocalPlayer local mouse = player:GetMouse() local clickEvent = tool.ClickEvent local function onActivate() local clickLocation = mouse.Hit clickEvent:FireServer(clickLocation) end tool.Activated:connect(onActivate)
But when i clicked in game i have this error: ClickEvent is not a valid member of Tool
But it should create a part at the place where you click.
Why it is not work?
-- Server Script local tool = script.Parent local clickEvent = tool:WaitForChild("ClickEvent") -- it is trying to find it before it loaded in, add your waitforchilds local clickEventConnection local function createPart(location) local part = Instance.new("Part") part.CFrame = location part.Parent = workspace end local function onClick(player, clickLocation) createPart(clickLocation) end local function onEquip() clickEventConnection = clickEvent.OnServerEvent:connect(onClick) end local function onUnequip() clickEventConnection:disconnect() end tool.Equipped:Connect(onEquip) tool.Unequipped:Connect(onUnequip) --make sure to uppercase connects, roblox prefers it for RBXScriptSignals
I edit code like this:
This is code of 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) createPart(clickLocation) end local function onEquip() clickEventConnection = clickEvent.OnServerEvent:connect(onClick) end local function onUnequip() clickEventConnection:disconnect() end Tool.Equipped:Connect(onEquip) Tool.Unequipped:Connect(onUnequip)
This is code of Local Script:
local Tool = script.Parent local player = game.Players.LocalPlayer local mouse = player:GetMouse() local clickEvent = Tool.Activated local function onActivate() local clickLocation = mouse.Hit clickEvent:FireServer(clickLocation) end Tool.Activated:connect(onActivate)
And now there is error: FireServer is not a valid member of RBXScriptSignal