Tool Giver for assigned team won't give tool


I have FinalisedFlames assigned to those tools and it wont appear in my backpack.

local coldrainTools = game.ServerStorage.ColdRainSkillTools
local aggressiveHeroTools = game.ServerStorage.AgressiveHeroSkillTools
local finalisedFlamesTools = game.ServerStorage.FinalisedFlamesSkillTools

-- Function to give tools to a player
function giveTools(player, toolFolder)
	for _, tool in ipairs(toolFolder:GetChildren()) do
		local clone = tool:Clone()
		clone.Parent = player.Backpack
	end
end

-- Function to remove tools from a player
function removeTools(player)
	for _, tool in ipairs(player.Backpack:GetChildren()) do
		tool:Destroy()
	end
end

-- Function to handle team switching
function onTeamChanged(player, team)
	removeTools(player) -- Remove any existing tools

	if team.Name == "ColdRain" then
		-- Give Coldrain team tools
		giveTools(player, coldrainTools)
	elseif team.Name == "Aggressivehero" then
		-- Give AggressiveHero team tools
		giveTools(player, aggressiveHeroTools)
	elseif team.Name == "FinalisedFlames" then
		-- Give FinalisedFlames team tools
		giveTools(player, finalisedFlamesTools)
	end
end

-- Connect the onTeamChanged function to the player's TeamChanged event
game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		character:WaitForChild("Humanoid").Died:Connect(function()
			removeTools(player)
		end)
	end)
	player.TeamChanged:Connect(function(team)
		onTeamChanged(player, team)
	end)
end)

-- Give initial tools to players when they join
game.Players.PlayerAdded:Connect(function(player)
	if player.Team == game.Teams.Coldrain then
		-- Give Coldrain team tools
		giveTools(player, coldrainTools)
	elseif player.Team == game.Teams.AggressiveHero then
		-- Give AggressiveHero team tools
		giveTools(player, aggressiveHeroTools)
	elseif player.Team == game.Teams.FinalisedFlames then
		-- Give FinalisedFlames team tools
		giveTools(player, finalisedFlamesTools)
	end
end)

Can anybody help me?
And I tested the “Fire splatter” and I want to see if the code is correct here. The animation triggers but doesnt do damage.

local animationId = "rbxassetid://13275733811"
local damageAmount = 10
local tool = script.Parent
-- Connect to the MouseClick event for the tool
tool.Activated:Connect(function()
	-- Get the player's character and humanoid
	local character = tool.Parent
	local humanoid = character:FindFirstChildOfClass("Humanoid")

	-- Play the animation
	local animation = Instance.new("Animation")
	animation.AnimationId = animationId
	local animationTrack = humanoid:LoadAnimation(animation)
	animationTrack:Play()

	-- Connect to the KeyframeReached event to detect when the animation hits another player
	animationTrack.KeyframeReached:Connect(function(keyframeName)
		if keyframeName == "HitPlayer" then
			-- Detect if the animation hit another player and deal damage if it did
			local hitPart = animationTrack.Animation.AnimationData:GetMarkerReachedSignal("HitPlayer"):Wait()
			local hitCharacter = hitPart.Parent
			local hitHumanoid = hitCharacter:FindFirstChildOfClass("Humanoid")
			if hitHumanoid and hitHumanoid.Health > 0 and hitCharacter ~= character then
				hitHumanoid:TakeDamage(damageAmount)
			end
		end
	end)
end)

Also how do I make an anti-cheat here? Like to prevent cooldown bypasses and stuff.

First, wrong category. #help-and-feedback:scripting-support

Second, we need more information about your “Tool Giver for assigned team won’t give tool” problem. I don’t quite understand it well. Can you provide more context?

My bad for the wrong category, don’t use the forum much. Ill change it. So I made a script that if you’re on a specific team you will get a specific set of tools. Ex: Team 1 has a gun while Team 2 has a sword. If you switch to team 1 you’ll receive a gun. And if you switch to team 2 it will delete that gun from your backpack, and replace it with a sword. I also have an updated one but failed to work.

	for _, t in pairs(game:GetService("Teams"):GetChildren()) do
		if t.TeamColor == color then
			return t
		end
	end
	return nil
end

function onSpawned(plr)
	local team = teamFromColor(plr.TeamColor)
	local teamFolderName = ""
	if team.Name == "Maroon" then
		teamFolderName = "AgressiveHeroSkillTools"
	elseif team.Name == "Deep Blue" then
		teamFolderName = "ColdRainSkillTools"
	elseif team.Name == "Permission" then
		teamFolderName = "FinalisedFlamesSkillTools"
	end
	local toolFolder = game:GetService("ServerStorage"):FindFirstChild(teamFolderName)
	if toolFolder then
		for _, c in pairs(toolFolder:GetChildren()) do
			c:Clone().Parent = plr.Backpack
		end
	end
end


function onChanged(prop, plr)
	if prop == "Character" then
		onSpawned(plr)
	end
end

function onAdded(plr)
	plr.Changed:connect(function(prop)
		onChanged(prop, plr)
	end)
end

game.Players.PlayerAdded:connect(onAdded)
  1. I found out the animation of the script for the skills
local damageAmount = 10
local tool = script.Parent
-- Connect to the MouseClick event for the tool
tool.Activated:Connect(function()
	-- Get the player's character and humanoid
	local character = tool.Parent
	local humanoid = character:FindFirstChildOfClass("Humanoid")

	-- Play the animation
	local animation = Instance.new("Animation")
	animation.AnimationId = animationId
	local animationTrack = humanoid:LoadAnimation(animation)
	animationTrack:Play()

	-- Connect to the KeyframeReached event to detect when the animation hits another player
	animationTrack.KeyframeReached:Connect(function(keyframeName)
		if keyframeName == "HitPlayer" then
			-- Detect if the animation hit another player and deal damage if it did
			local hitPart = animationTrack.Animation.AnimationData:GetMarkerReachedSignal("HitPlayer"):Wait()
			local hitCharacter = hitPart.Parent
			local hitHumanoid = hitCharacter:FindFirstChildOfClass("Humanoid")
			if hitHumanoid and hitHumanoid.Health > 0 and hitCharacter ~= character then
				hitHumanoid:TakeDamage(damageAmount)
			end
		end
	end)
end)


Doesnt work.

My recommendation on how to do this:

local teams = {["Maroon"]="AgressiveHeroSkillTools", ["Deep Blue"]="ColdRainSkillTools", ["Permission"]="FinalisedFlamesSkillTools"}
game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		--to be honest, I didn’t understand what you want, or look for teams by colors, or by names, I did by names
		local teamFolderName = teams[plr.Team.Name]
		if not teamFolderName then return end
		local toolFolder = game:GetService("ServerStorage"):FindFirstChild(teamFolderName)
		if toolFolder then
			for _, c in pairs(toolFolder:GetChildren()) do
				c:Clone().Parent = plr.Backpack
			end
		end
	end)
end)

(to be honest, I didn’t understand what you want, or look for teams by colors, or by names, I did by names)

By name would be more accurate tbh. Ill try this script right now, thanks for helping me.

Edit: Didnt replace the tools in my backpack. Ill give you a copy of my game.

CopyGameToolTeamHandler.rbxl (38.7 KB)

Just send me an ss of the updated script(I deleted some stuff for personal reasons) also you can run this through the totalvirus web file scanner if you don’t trust me.

Reason I gave you a copy is so you can see and get a better perspective of my case.