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

Created part doesn't do damage?

I tried creating a new part using a script, but it is supposed to kill the player who touches it, but it doesn't. Here is the code.

function Attack1()
local Random1 = math.random(-100, -46)
local Random2 = math.random(-186, -161)
script.Parent.BrickColor = BrickColor.new("Bright red")
bullet = Instance.new("Part", workspace)
bullet.Shape = Enum.PartType.Ball
bullet.BrickColor = BrickColor.new("Neon orange")
bullet.Material = Enum.Material.Neon
bullet.Position = Vector3.new(Random1, 100, Random2)
bullet.Size = Vector3.new(20, 20, 20)
function onTouch(part) 
	local humanoid = bullet.Parent:FindFirstChild("Humanoid") 
	if (humanoid ~= nil) then
	humanoid.Health = 0
end 
end

script.Parent.Touched:connect(onTouch)
wait(5)
bullet:Destroy()
end
while true do
	Attack1()
end

1 answer

✓ Accepted answer
while true do
	spawn(function()
		local Random1 = math.random(-100, -46)
		local Random2 = math.random(-186, -161)
		script.Parent.BrickColor = BrickColor.new("Bright red")
		local bullet = Instance.new("Part", workspace)
		bullet.Shape = Enum.PartType.Ball
		bullet.BrickColor = BrickColor.new("Neon orange")
		bullet.Material = Enum.Material.Neon
		bullet.Position = Vector3.new(Random1, 100, Random2)
		bullet.Size = Vector3.new(20, 20, 20)
		local connection = bullet.Touched:Connect(function(object)
			local humanoid = object.Parent:FindFirstChild("Humanoid") 
    		if humanoid then
    			humanoid.Health = 0
			end
		end)
		wait(5)
		if bullet then
			bullet:Destroy()
		end
		connection:Disconnect()
	end)
	wait()--Please insert how much time for each bullet to appear.
end

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