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

How do I make something happen when clicking a tool?

I'm trying to make a tool that confuses players In an area when clicked, except for the person who clicked it. I dont know what to use.

local tool = script.Parent
tool.Equipped:connect(function(mouse)
	
end)

I have this so far, but I think It's incorrect.

1 answer

You are correct so far; what you want to do next is connect to the Button1Down event:

local tool = script.Parent
tool.Equipped:connect(function(mouse)
	mouse.Button1Down:connect(function()

	end)
end)

For making other players walk away, iterate through each other player in the game and call Humanoid:MoveTo to tell them to walk:

local tool = script.Parent
local player=game.Players.LocalPlayer
local radius=30

local t=player.Character:WaitForChild("Torso")
tool.Equipped:connect(function(mouse)
	mouse.Button1Down:connect(function()
		for _,v in pairs(game.Players:GetPlayers())do
			if v~=player and v.Character then
				local char=v.Character
				if char:FindFirsrtChild("Torso")and char:FindFirstChild("Humanoid")then
					local torso,h=char.Torso,char.Humanoid
					if(torso.Position-t.Position).magnitude<=radius then
						h:MoveTo(torso.Position+CFrame.new(t.Position, torso.Position).lookVector*radius,t)
					end
				end
			end
		end
	end)
end)

7 comments

0

And what would I use to confuse ( make them move away from the person that clicked it) players.

0

clicked what?

0

The tool

0

so whenever someone clicks, every other player in the game starts walking directly away from them?

0

Well I guess everyother player in a certain radius

0

Iterate through every other player, check if they're within the radius, use Humanoid:MoveTo to make them walk to some point.

0

I've never used that before. Can you give me an example?

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