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

Touched: won't trigger when a player walks through part?

I created a raycast that makes a part and after .5 seconds i create another part with the same CFrame and size of the first one, but alot bigger. (it's a laser beam cannon im making)

However, the touched event is only working when the person who shot the laser walks through it, and not the other players.

			local beamDamage = Instance.new("Part")
			beamDamage.Parent = workspace
			game:GetService('Debris'):AddItem(beamDamage, 20)
			beamDamage.Transparency = .25
			beamDamage.Anchored = true
			beamDamage.CanCollide = false
			beamDamage.Material = 'Neon'
			beamDamage.CFrame = beam.CFrame
			beamDamage.Size = Vector3.new(5,5,distance+20)
			beamDamage.BrickColor = BrickColor.new("Really red")			

			beamDamage.Touched:Connect(function(hit)
				print('touched')
				if hit.Parent then
					local humanoid = part.Parent:FindFirstChild('Humanoid')
					if humanoid then
						if canDamage == true then
							humanoid:TakeDamage(80)
							canDamage = false
						end
					end
				end
			end	)			
	
			wait(3)
			canDamage = true

this is a local script, but FE is off.

2 comments

0

Where do you set "beam"? Line 8 -- "Distance"? Line 9 -- "part"? Line 15

0

Sorry, that stuff is all created in the script. I just didnt post the whole thing because it would be alot. However, the beamDamage CFrame and size all works. it just doesnt trigger the touched event.

1 answer

You seem to be searching for the Humanoid from part's Parent, but part has not been defined. You should be looking in hit's Parent.

local beamDamage = Instance.new("Part")
beamDamage.Parent = workspace
game:GetService('Debris'):AddItem(beamDamage, 20)
beamDamage.Transparency = .25
beamDamage.Anchored = true
beamDamage.CanCollide = false
beamDamage.Material = 'Neon'
beamDamage.CFrame = beam.CFrame
beamDamage.Size = Vector3.new(5,5,distance+20)
beamDamage.BrickColor = BrickColor.new("Really red")    
local canDamge = true     

beamDamage.Touched:Connect(function(hit)
	if not canDamage then return end canDamage = false;
	local humanoid = hit.Parent:FindFirstChild('Humanoid')
	if humanoid then
		humanoid:TakeDamage(80)
	end
	wait(3)
	canDamage = true;
end )           

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