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

I know how to make a brick that damages you, but does anyone knows how to do this?

How do i make a brick that damages (not killls) a players in a specific team and that doesnt damages players from a other specific team? I am not an expert in scripts im sorry. This is the script that i used:

local Debounce = false

script.Parent.Touched:connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and Debounce == false then
		Debounce = true
		hit.Parent.Humanoid:TakeDamage(10)
		wait (1)
		Debounce = false
	end
end)

1 comment

0

oh. try using teamservice.

2 answers

✓ Accepted answer

Your script to cause damage is correct, but this script can sometimes cause an error.

For example: If a player touches the piece, but the one who touched it first is, say your backpack or part of your wing.

The script will return an error and break.

To check the teams, you must check the color of the Player's team.

You can do the following

local Debounce = false

script.Parent.Touched:Connect(function(Hit)
	if Debounce == false then
	Debounce = true
	local Character = Hit.Parent
	local Player = game.Players:GetPlayerFromCharacter(Character)
		if Player and Player.TeamColor == BrickColor.new("Team Color") then
			-- You need to put the same color of the Team.
			local Humanoid = Player.Character:FindFirstChild("Humanoid")
			Humanoid:TakeDamage(10)
		end

		wait(1)

		Debounce = false
	end
	
end)

Any questions, you can ask.

:)

7 comments

1

It can't cause an error, it uses "FindFirstChild" which returns a bool if it's found, so if it's true it will do it ( how will this error lol ? )

0

Truth... Now that I'm thinking... lol. But I worried because when I did it, sometimes it would return an error, but it stopped when I switched to this system, so I tried to advance things, you know?

0

It works thank you!

0

With that i can finally complete my game now! :D

0

:)

0

Can i play?

0

Of course! But i am updating the game and its private now

You can do this by using team color or team name ( name is most accurate in my opinion )

local Debounce = false

script.Parent.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") and Debounce == false then
        if game:GetService("Players"):FindFirstChild(hit.Parent.Name) then
          if not game:GetService("Players"):FindFirstChild(hit.Parent.Name).Team.Name == "TEAMNAME" then return end
          Debounce = true
          hit.Parent.Humanoid:TakeDamage(10)
          wait (1)
          Debounce = false
        end
    end
end)

3 comments

0

Ok i'll try it Ty!

0

hope it works.

0

Oof not working, thanks anyways!

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