Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

ClickEvent is not a valid member of Tool?

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?

2 comments

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

0

You sure you have a RemoteEvent named ClickEvent in the tool?

2 answers

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

2 comments

0

When i use this i have the same error:

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

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

This discussion is preserved as it was. New answers, comments, and votes are closed.