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

Help with kill script? [DONE]

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

2 comments

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?

0

I want them to die when my model ( model is a person ) touches them.

2 answers

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)

1 comment

0

Okay thx

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)

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