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

How do I make this script not only hurt players, but aliens in my game as well?

This is a script from an owner only door, but there are aliens in my game that I would like to be killed from the lasers too. I tried deleting the "plr" part so that it would just set all humanoids health to zero ,and I tried just identifying an alien also as a plr by using

game. Aliens.("Alien")

but that didn't work either. I am new to scripting so sorry if I am doing this completely wrong, but what is the most efficient way of doing this?

val = script.Parent.Parent.Parent.Value

function touc(part)
	local plr = game.Players:FindFirstChild(part.Parent.Name)
	if plr then
		local h = part.Parent:FindFirstChild("Humanoid")
		if h then
			if val.Value == true then
				if part.Parent.Name ~= script.Parent.Parent.Parent.Parent.Parent.Owner.Value.Character.Name then
				h.Health = 0
				end
			end
		end
	end
end
script.Parent.Touched:connect(touc)

1 answer

✓ Accepted answer

What you can do is, if the alien has a humanoid in it

val = script.Parent.Parent.Parent.Value -- guessing this is if it is on or not?

function touc(part)
	if val.Value == true then -- check to see if it is on
		if part.Parent then -- check to see if it has a parent
			if part.Parent:FindFirstChild("Humanoid") then
				local humanoid = part.Parent:FindFirstChild("Humanoid")
				if part.Parent.Name ~= script.Parent.Parent.Parent.Parent.Parent.Owner.Value.Character.Name then
					humanoid.Health = 0 
				end
			end
		end
	end
end

script.Parent.Touched:Connect(touc)

21 comments

0

says that owner is not a valid member of folder, but I think I need to have the plr part because I think it makes sure that only the owner can walk through.

0

Are you sure script.Parent.Parent.Parent.Parent.Parent.Owner.Value.Character.Name is a thing? That was from your code that i just copied assuming it was correct.

0

yes it worked beforehand. I think it makes sure that the owner won't take damage...

0

yes, that is the goal. The way we should be doing that is... Check if the person's name is the same as the name of the Owner.

0

However, the error you are getting is saying that script.Parent.Parent.Parent.Parent.Parent (Does not lead to an object called "Owner")

0

follow through your explorer and tell me what script.Parent.Parent.Parent.Parent.Parent is

0

Ok...the first parent is the pipe in which the script is in, second is the lasers in which the set of pipes are in, third is th owner only door that the lasers are a part of, fourth is the purchases that the owner only door is a part of, fifth is the tycoon it is in. Then it finds the Owner Value in the tycoon. That is set to change to whoever owns the tycoon

0

so is the main parent of the tycoon a folder? because that's what it says the 5th parent is. And once it gets there, it looks for an object called "Owner" and says it cannot find it.

0

yes

0

Also, is the "Owner" object a StringValue, ObjectValue, etc?

0

Look through it again and make sure "Owner" is in that folder, and not in a child of that folder

0

owner is directly is that folder and what is a String or Object Value? Sorry, I'm new

0

nvm I found it... Object Value

0

is Owner capitalized?

0

yup

0

Man, i would love to help this further but if the error is saying that owner is not a valid member of folder, then something must be wrong with that line.

0

when you play the game open up that tycoon (while actually playing) and see if there is an "Owner" in the tycoon cause the error says it aint there

0

alright I just figured out the problem: when I was testing it I just ungrouped the purchased model so that I could skip right to the end of the tycoon instead of having to go through the whole thing because I have a script that  removes everything in the purchases model but puts it back when it is bought. by doing this, I broke your beautiful script with my blindness.

0

I tested it and it works great sorry for wasting your time...

0

Hahaha no worries, I'm glad you found out what happened though! Good job. If I helped at all with the original code would you mind accepting the answer?

0

of course

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