Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do I make something happen when clicking a tool?

Asked by 8 years ago

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

Log in to vote
1
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
8 years ago

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)
0
And what would I use to confuse ( make them move away from the person that clicked it) players. 64batsalex 45 — 8y
0
clicked what? 1waffle1 2908 — 8y
0
The tool 64batsalex 45 — 8y
0
so whenever someone clicks, every other player in the game starts walking directly away from them? 1waffle1 2908 — 8y
View all comments (3 more)
0
Well I guess everyother player in a certain radius 64batsalex 45 — 8y
0
Iterate through every other player, check if they're within the radius, use Humanoid:MoveTo to make them walk to some point. 1waffle1 2908 — 8y
0
I've never used that before. Can you give me an example? 64batsalex 45 — 8y
Ad

Answer this question