Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 7 years ago
Edited 7 years ago

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

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 Bantool 11 — 7y

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
7 years ago
Edited 7 years ago

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)
0
So would i put that onto a whole new script or..? DeveloPatter 23 — 7y
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? DeveloPatter 23 — 7y
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. Goulstem 8144 — 7y
Ad

Answer this question