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

How to check if a part goes through another part? (Like space invaders, when a bullet hits an enemy)

I have a space-invader like game, when a part goes though another (both CFramed) The enemy gets killed (:Destroy())

-- Basic Script I am using
script.Parent.Touched:connect(function()
	script.Parent:Destory()
end)

I was informed somewhere that :Touched event doesn't work with parts being CFramed, in my case both parts are

2 comments

0

I would test before making assumptions. It used to be the case that CFrames didn't fire Touched events, but I'm not sure now.

0

Yeah it still doesn't, I tried before

1 answer

I dont really know how to do that, but I would recommend simply using a part to do the .Touched event. To do that you can use a script like this:

local Part = Instance.new("Part", workspace)
	Part.Size = Vector3.new(0.1,0.1,0.1)
	Part.Shape = ("Ball")
	Part.Position = Vector3.new(-3.5,0.5,4.5)
	Part.CFrame = tool.Handle.CFrame
	Part.CFrame = CFrame.new(Part.Position,mouse.Hit.p)
	local v = Instance.new("BodyVelocity", Part)
	v.velocity = Part.CFrame.lookVector *90
	v.maxForce = Vector3.new(math.huge, math.huge, math.huge)

Of course, I am also new to scripting so dont expect much from me. I hope this helped.

1 comment

0

How is your script helping him understand the touched event? Am I missing something here

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