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

Help with Hyperlaser and destroying laser?

local function OnTouched(shot, otherPart)
	local character, humanoid = FindCharacterAncestor(otherPart)
	if otherPart.ClassName == "Part" then
		if otherPart.Name ~= "Handle" then
			shot:Destroy()
		end
	end
	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
		end
		Dematerialize(character, humanoid, otherPart)
	end
end

This is a little part of the script of the Hyperlaser. I have editted so if the bullet hits a part then it destroys itself, but it destroys objects if they have humanoids inside them. I have a tycoon with humnaoids in all the buttons and if you shoot the buttons then they get destroyed. Please help so it checks to if the bullet collides with a players humanoid and not a part humanoid?

1 answer

✓ Accepted answer

You could try using the Players:GetPlayerFromCharacter method to see if something is an actual character belonging to a player. To do that, replaceif character and humanoid and character ~= Character then by the following:

if character and humanoid and character ~= Character and Game:GetService("Players"):GetPlayerFromCharacter(character) then

Alternatively, if you want it to destroy anything that has a health bar (which is not the case for the buttons), you could try checking the Humanoid.MaxHealth property. If it is 0 or math.huge, the humanoid will not have a health bar. In that case, replace the aforementioned line by this:

if character and humanoid and character ~= Character and humanoid.MaxHealth ~= 0 and humanoid.MaxHealth ~= math.huge then

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