✓ Accepted answer
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.
2 comments
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
You can't click a block when you're holding a tool