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