0

# My script doesnt detect when a player is holding a tool and then clicks a block?

I used what I learnt in parts here the hierarchy: https://gyazo.com/34ee83ce5fb32daa33cd0aa7de19b3e1 Any help appriciated

script.Parent.Equipped:Connect(function()
local Helper = game.Workspace.ToolEventHelper

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("RemoteEventToolTest")

Helper.OnMouseClick:Connect(function()

Helper.Transparency = 1

end)
remoteEvent:FireServer()
end)


0
I learned today that you need a server-sided script to handle remote event fires, its called OnServerEvent, do you have a script with that? if so, please add it matiss112233 258 — 2y
0
You can't click a block when you're holding a tool TheNINJA152 85 — 2y

1
2 years ago

First, create a local script within the Tool:

local Player = game:GetService("Players").LocalPlayer
local Mouse = Player:GetMouse()

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEventToolTest")
local Tool = script.Parent

Tool_Forage.Activated:Connect(function()
local Target = Mouse.Target
if Target then
if Target:FindFirstChild("ClickDetector") then
RemoteEvent:FireServer(Target)
end
end
end)



Now, what this does is the Tool will detect if it is activated (clicked). It will then detect the Target your mouse is clicking. If the Target has a 'ClickDetector' within it, then it will fire the RemoteEvent.

Now, create a server script that contains this:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEventToolTest")

local function ToolActivated (Target)
local Target_Workspace = game.Workspace:FindFirstChild(Target)
if Target_Workspace then
Target_Workspace.Transparency = 0.5
else
print("Target is not existing in the Workspace.")
end
end

RemoteEvent.OnServerEvent:Connect(ToolActivated)


This server script will fire the function 'ToolActivated' whenever the local script within the tool fires the RemoteEvent. The tool then passes the parameter 'Target'. This Target then gets passed on to the server script. Now, the server script will find the 'Target' on the Workspace, and sets its Transparency to the indicated value. If the Target cannot be found, it will print out 'Target is not existing in the Workspace.' Note that since that a 'server-sided script' sets the Transparency, all the Players will see it.

0
With a bunch of trouble shooting etc it worked! thank you for putting effort in and helping, I really appreciate it. Hope you have a great day :) snipperdiaper 120 — 2y