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

Help with kill script? [DONE]

Asked by 10 years ago

Please help, i want to make a script so one of my models can try to kill people, but i have no idea how.

0
More specifics? Do you want a player to die when they touch a specific brick? Or do you want people to die when they get near the model? jav2612 180 — 10y
0
I want them to die when my model ( model is a person ) touches them. gtaboss1 0 — 10y

2 answers

Log in to vote
1
Answered by
Ekkoh 635 Moderation Voter
10 years ago

It depends on how you want it to work for the most part. A couple ways to damage/kill a player are-

Character:BreakJoints()
Character.Humanoid:TakeDamage(50)
Character.Humanoid.Health = 0

To sense touches you should use the Touched event of a Part. If you're making some type of AI, I'd use the Touched event of both its arms and make them damage players when touched. The script might look something like this-

local AI = script.Parent
local LeftArm = AI:WaitForChild("Left Arm")
local RightArm = AI:WaitForChild("Right Arm")

function ArmTouched(part)
    local hum = part.Parent:FindFirstChild("Humanoid")
    if hum then
        -- a character must've touched the part
        hum:TakeDamage(math.random(5, 25))
    end
end

LeftArm.Touched:connect(ArmTouched)
RightArm.Touched:connect(ArmTouched)
0
Okay thx gtaboss1 0 — 10y
Ad
Log in to vote
0
Answered by
jav2612 180
10 years ago

This will make any part in the model(script.Parent) kill people.


model = script.Parent function Touched(part) if part.Parent:FindFirstChild("Humanoid") ~= nil then part.Parent.Humanoid.Health = 0 end end function ConnectParts(obj) if obj then if obj:IsA("Part") then obj.Touched:connect(Touched) else if #obj:GetChildren() > 0 then for i, v in pairs(obj:GetChildren()) do ConnectParts(v) end end end end end ConnectParts(model)

Answer this question