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

How do i make a body part do damage for a Combat script?

I have no idea on what to do since i'm a starting Scripter, Can anyone help me out?

1 comment

0

You can make it so whenever it is touched by another player that player will get damaged but make sure to make it that the person who touches the body part isnt you

1 answer

✓ Accepted answer

You can use the Touched event to determine if a player is touched by the body part. Manipulate their Humanoid object's Health property, then.

local person = workspace.Goulstem.HumanoidRootPart --Part to affect
local damage = 5 --How much it damages
local db = false --Debounce

person.Touched:Connect(function(hit) --Touched event 'hit' is what touched
	--make sure it's not yourself
	if hit:IsDescendantOf(person.Parent) then return end
	if not db then
		db = true
		local h = hit.Parent:FindFirstChild("Humanoid") --Check for humanoid
		if h then
			h:TakeDamage(damage) --Damage player
		end
		db = false
	end
end)

3 comments

0

So would i put that onto a whole new script or..?

0

Wait nevermind i figured it out i just need to know how i would pick out the player that's playing, Would i do: local Char = game.Players.LocalPlayer.Character; and then change the person variable to: person = game.Workspace.Char.HumanoidRootPart?

0

If you did it on the client you'd have to use Remotes, so you can use a PlayerAdded and CharacterAdded event on the server to get the person.

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