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

Help with :Destroy()? [UNSOLVED]

local function OnTouched(shot, otherPart)
	local character, humanoid = FindCharacterAncestor(otherPart)
	if character and humanoid and character ~= Character then
		ApplyTags(humanoid)
		if shot then
			local hitFadeSound = shot:FindFirstChild(HitFadeSound.Name)
			if hitFadeSound then
				hitFadeSound.Parent = humanoid.Torso
				hitFadeSound:Play()
			end
			shot:Destroy()
		end
		Dematerialize(character, humanoid, otherPart)
	elseif otherPart.ClassName == "Part" then
		shot:Destroy()
	end
end

I have a laser and I want it to destory() the bullet if it touches a part, cause right now it goes through the part. Any help with this? It isn't showing any output, so don't know what the error is. Inside a LocalScript.

1 answer

✓ Accepted answer

You simply forgot the Event part of the function. Just put this in.

script.Parent.Touched:connect(onTouched) -- assuming the script is in the part that you want to be touched 

7 comments

0

that still dosent work :/ I just have a LocalScript inside a Tool.

0

OH, that's the problem. The function fires when the tool is touched. Just change the "script.Parent" part to the object you want to be touched (i.e. game.Workspace.laser)

0

-Edit- I change it to the whole script, I am just using ROBLOX's HyperLaser, I think it should be around the bottom where it should be to destory if it doesnt hit a player but a part. Can you just have a quick look?

0

Oh jeez, that's a lot of code. I most likely won't be able to detect a problem here.

0

maybe around 149 163 abouts

0

I am pretty sure it has to be placed 143 -163 cause thats where it kills the player. I just dont know how to detect if the bullet hit a part instead of a player. Please just ook at that 20 lines of code

0

I editte dagain with just the piece of code I need. I added an attemp on lines 14-15 but that just destroys the bullet the second is eaves the barrel

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