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

ClickEvent is not a valid member of Tool?

Asked by 5 years ago

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

Screen

But it should create a part at the place where you click.

Why it is not work?

0
There is no "ClickEvent" for a tool. You could use the Button1Click event of the mouse, adn then just check if they have the tool equipped Shawnyg 4330 — 5y
0
You sure you have a RemoteEvent named ClickEvent in the tool? Torren_Mr 334 — 5y

2 answers

Log in to vote
0
Answered by
Imperialy 149
5 years ago
-- 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
0
When i use this i have the same error: InferusAnima 0 — 5y
0
But, also when the test start i have this warning: Infinite yield possible on 'Workspace.Tool:WaitForChild("ClickEvent")'. I think maybe it's the outdated method that not working InferusAnima 0 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

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

Screen

Answer this question