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

Creating a new part that hurts 49 health each hit?

function Explode()

	local count = 5


	for i=1,count do
		local p = Instance.new("Part")
		p.BrickColor = BrickColor.new("White")
		p.formFactor = 2
		p.Size = Vector3.new(1,.4,1)
		p.Material = Enum.Material.Ice
		p.TopSurface = 0
		p.BottomSurface = 0
		
		p.Velocity = arrow.Velocity * (4 + (math.random() *2))
		p.RotVelocity = Vector3.new(math.random(-20,20), math.random(-20,20), math.random(-20,20))
		p.Position = arrow.Position + (arrow.Velocity * math.random() * .05) + Vector3.new(0,math.random() * 3, 0)
		p.Parent = game.Workspace

		debris:AddItem(p, 60)
	end

end

Thats the part I'm having issues with. It works but I want the part thats created (p) to have a script that when it touches a player it hits 49. I can't figure out a script to hurt just 49 and I don't know how to have it in the part thats created either. :/

1 comment

0

Could I just clone a gui from lighting into that part? By using 3Hit = game.Lighting.3Hit:Clone() (NEXT LINE) 3Hit.Parent = p

1 answer

function Explode()

    local count = 5


    for i=1,count do
        local p = Instance.new("Part")
        p.BrickColor = BrickColor.new("White")
        p.formFactor = 2
        p.Size = Vector3.new(1,.4,1)
        p.Material = Enum.Material.Ice
        p.TopSurface = 0
        p.BottomSurface = 0

	p.Touched:connect(function (part)
		pcall(function () --Makes sure when there is no parent it doesn't disconnect the event.
			if part.Parent:FindFirstChild("Humanoid") ~= nil then
				part.Parent:FindFirstChild("Humanoid") :TakeDamage(49) -- This will damage the humanoid if it doesn't have a forcefield. If you just want it to hurt you would change it to part.Parent:FindFirstChild("Humanoid") .Health = part.Parent:FindFirstChild("Humanoid")  - 49
			end
		end)
	end)

        p.Velocity = arrow.Velocity * (4 + (math.random() *2))
        p.RotVelocity = Vector3.new(math.random(-20,20), math.random(-20,20), math.random(-20,20))
        p.Position = arrow.Position + (arrow.Velocity * math.random() * .05) + Vector3.new(0,math.random() * 3, 0)
        p.Parent = game.Workspace

        debris:AddItem(p, 60)
    end

end

There you go!

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