How to make a block only clickable while holding a certain tool?

@Randy_Moss made a script that should work. Try it out.

It works, but stuff happens prints every time you click it, even when youre not holding the tool. @Randy_Moss

Then you can just check if the player has the tool equipped on the remote side.

How would u do that? 30 charsacters

Lets take a look at Randy’s script.

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local tool = --your tool

tool.Activated:Connect(function()
    script.Parent.Set:FireServer(mouse.Target, tool)
end) 

Now for the server side:

Set.OnServerEvent:Connect(function(player,Target, tool)
      if Target and Target.Name == "name of your part" and tool.Equipped == true then
          print ("stuff happens")
      end
end)

@Randy_Moss, it just comes up with one more error
[12:24:43.890 - Players.octavodad.Backpack.ToolThatClickBlock.Script:2: attempt to index nil with ‘GetMouse’]

Can you post the code?
Also make sure it’s a local script.

1 Like

Ok. The local script

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local tool = player.Backpack.ToolThatClickBlock

tool.Activated:Connect(function()
    script.Parent.Set:FireServer(mouse.Target, tool)
end) 

mouse.Button1Down:Connect(function()
    script.Parent.Set:FireServer(mouse.Target)
end) 

and the script

local player = game.Players.LocalPlayer

Set = script.Parent.Set


Set.OnServerEvent:Connect(function(player,Target, tool)
      if Target and Target.Name == "Block" and tool.Equipped == true then
          print ("stuff happens")
      end
end)

remove local player = game.Players.LocalPlayer in the script
replace local tool = player.Backpack to
local tool = script.Parent

1 Like

Then what do I replace all the words of “mouse” with?

@Randy_Moss, it is now coming up with
[12:33:29.161 - Players.octavodad.Backpack.ToolThatClickBlock.LocalScript:6: attempt to index nil with ‘Target’]

You’re clearly not able to script this yourself. This category is for help and suggestions, not hiring people to do the work for you. You should go to #collaboration:recruitment for that (and pay someone to script it for you).

Alternatively, you could learn how to do Lua, via the Developer Hub.

2 Likes

I fixed it! Thanks to all your help! 30chars