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

My anti team kill script is having problems with fulfilling the command :/ help?

function HIT_HANDLE(hit, dmg, tags)
	if hit.Parent:FindFirstChild("Humanoid") then
		hit.Parent.Humanoid:TakeDamage(75)
	    PlaySound("Hit")
	    PlaySound("Dead")
	end
end

So basically this is the original part of the script where if the tool (the throwing knife is the tool) hits a player, it deals 75 damage, what I have been trying to do is set up the script so that if the player the throwing knife hits is a teammate, it wont do damage, and only would if it wasn't a teammate, this was my best attempt at it and still was having troubles... :/ :

function HIT_HANDLE(hit, dmg, tags)
	if hit.Parent:FindFirstChild("Humanoid") then
		if hit.Parent.TeamColor ~= Player.TeamColor then
			hit.Parent.Humanoid:TakeDamage(75)
	   		 PlaySound("Hit")
		end
	end
end

Thanks in advance to anyone who helps me figure this out!

1 comment

1

Characters do not have a TeamColor. View the output.

1 answer

✓ Accepted answer

Like cabbler said, you can't change the Player's TeamColor by just getting the Character. So then we use this function called ":GetPlayerFromCharacter()".

function HIT_HANDLE(hit, dmg, tags)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- hit.Parent is the character but we use his function to get the player's character.
    if hit.Parent:FindFirstChild("Humanoid") and player then -- we will just check if it is a player too.
        if player.TeamColor ~= Player.TeamColor then --Not sure what the "Player" is, I left that how it is.
            hit.Parent.Humanoid:TakeDamage(75)
             PlaySound("Hit")
        end
    end
end

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