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

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

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.

2 comments

0

Connect a table to an activation event using .Character

0

Not helpful, nor does it make any sense at all...

1 answer

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

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