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

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)

2 comments

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

0

You can't click a block when you're holding a tool

1 answer

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

1 comment

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

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