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

How Would I get a player's humanoid when the player has clicked to activate a tool?

Asked by
iLordy 27
4 years ago

What I would like to know is how would I be able to get a player's humanoid and store into a variable when the player has activated a tool in their starter pack such as: shooting a gun, lunging a sword, dropping a bomb.

0
Connect a table to an activation event using .Character Thesquid13 301 — 4y
0
Not helpful, nor does it make any sense at all... mc3334 649 — 4y

1 answer

Log in to vote
0
Answered by
mc3334 649 Moderation Voter
4 years ago

This is a broad topic, so I will give you an example.

SETUP

1) Create a server script under server script service

2) Create a bindable event under replicated storage

-Name it "ToolActivated"

3) Create a script under each tool you want to detect the activation on

SCRIPTING

Step 1 server script:

ev = game:GetService("ReplicatedStorage"):WaitForChild("ToolActivated")
playersActivated = {}

ev.Event:Connect(function(plrName)
    local InTable = false
    for _,v in pairs(playersActivated) do
        if v == plrName then
            InTable = true
        end
    end
    if InTable == true then return end
    table.Insert(playersActivated,plrName)
end)

while wait(10) do  --This just prints who has activated a tool every 10 seconds
    local PLRstring = ""
    for i,v in pairs(playersActivated) do
        if i == #playersActivated then
            PLRstring = PLRstring..v
        else
            PLRstring = PLRstring..v..", "
        end
    end
    print("The following players have activated a tool: "..PLRstring
end

Step 3 EACH server script:

EV = game:GetService("RepliactedStorage"):WaitForChild("ToolActivated")
tool = script.Parent

tool.Activated:Connect(function()
    EV:Fire(tool.Parent.Name)
end)

I hope my answer helped! ~mc3334

Ad

Answer this question