Trying to give a tool when a player touches a part for a specific team

omg its mb on my end, two gk tools

1 Like
local repStorage = game:GetService("ReplicatedStorage")
local tool = repStorage:WaitForChild("GK") --change to name of tool
local players = game:GetService("Players")
local part = workspace:WaitForChild("GoaliePart")
local partPlayers = {}

part.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("HumanoidRootPart") then
		local player = players:GetPlayerFromCharacter(hit.Parent)
		print(player.Team)
		if player.TeamColor == BrickColor.new("Forest green") then --change to color of team
			table.insert(partPlayers, player)
			local toolClone = tool:Clone()
			toolClone.Parent = player:WaitForChild("Backpack")
		end
	end
end)

part.TouchEnded:Connect(function(hit)
	if hit.Parent:FindFirstChild("HumanoidRootPart") then
		local player = players:GetPlayerFromCharacter(hit.Parent)
		if player.TeamColor == BrickColor.new("Forest green") then --change to color of team
			for i, v in pairs(partPlayers) do
				if v.Name == player.Name then
					table.remove(partPlayers, i)
					for i, v in pairs(player:WaitForChild("Backpack"):GetChildren()) do
						if v.Name == "GK" then --change to name of tool
							v:Destroy()
						end
					end
				end
			end
		end
	end
end)

I’ve changed the references & stuff with what I think should match the game.

1 Like

works, thx but it gives you more than one tool

1 Like