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

Made a crowbar that damages players, but won't damage teammates, but appears to not work?

I made a crowbar that damages players however won't damages teammates but It appears to attempt with nil, I want It so when your not In a team you can damage everyone but If your not In a team you can damage players, but not your teammate

Script:

local tool = script.Parent
local Woosh = tool.Woosh
local PANSOUNDNOTCLICKBAIT = tool.PAN
local Slash = tool.Slash
local Debounce = false
local CanDamage = false

tool.Activated:Connect(function()
	if not Debounce then
		Woosh:Play()
		Debounce = true
		CanDamage = true
		local Hum = tool.Parent.Humanoid
		
		local AnimationTrack = Hum:LoadAnimation(Slash)
		AnimationTrack:Play()
		wait(0.9)
		CanDamage = false
		Debounce = false
	end
end)

tool.Handle.Touched:Connect(function(hit)
	local humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")
	
	local player1 = game.Players:GetPlayerFromCharacter(hit.Parent)
	local player2 = game.Players:GetPlayerFromCharacter(tool.Parent)
	
	if player1.TeamColor ~= player2.TeamColor then
		if humanoid and CanDamage == true then
			humanoid:TakeDamage(10)
			CanDamage = false
			humanoid.PlatformStand = true
			wait(1)
			humanoid.PlatformStand = false
		end
	end
end)

1 answer

✓ Accepted answer
local tool = script.Parent
local Woosh = tool.Woosh
local PANSOUNDNOTCLICKBAIT = tool.PAN
local Slash = tool.Slash
local Debounce = false
local CanDamage = false

tool.Activated:Connect(function()
	if not Debounce then
		Woosh:Play()
		Debounce = true
		CanDamage = true
		local Hum = tool.Parent.Humanoid
		
		local AnimationTrack = Hum:WaitForChild("Animator"):LoadAnimation(Slash)
		AnimationTrack:Play()
		task.wait(0.9)
		CanDamage = false
		Debounce = false
	end
end)

tool.Handle.Touched:Connect(function(hit)
	local player1 = game.Players:GetPlayerFromCharacter(tool.Parent)
	local player2 = game.Players:GetPlayerFromCharacter(hit.Parent)
	
	if (player1 ~= nil) and (player2 ~= nil) then
		local humanoid = (player2.Character or player2.CharacterAdded:Wait()):FindFirstChildWhichIsA("Humanoid")
		
		if (player1.TeamColor ~= player2.TeamColor) then
			if (humanoid ~= nil) and CanDamage == true then
				humanoid:TakeDamage(10)
				CanDamage = false
				humanoid.PlatformStand = true
				task.wait(1)
				humanoid.PlatformStand = false
			end
		end
	end
end)

1 comment

0

Yo thanks! I was just wondering how to modify It so It damages NPCS as well

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