Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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)
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. KingCheese13 21 — 5y
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. PoePoeCannon 519 — 5y
0
yes it worked beforehand. I think it makes sure that the owner won't take damage... KingCheese13 21 — 5y
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. PoePoeCannon 519 — 5y
View all comments (17 more)
0
However, the error you are getting is saying that script.Parent.Parent.Parent.Parent.Parent (Does not lead to an object called "Owner") PoePoeCannon 519 — 5y
0
follow through your explorer and tell me what script.Parent.Parent.Parent.Parent.Parent is PoePoeCannon 519 — 5y
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 KingCheese13 21 — 5y
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. PoePoeCannon 519 — 5y
0
yes KingCheese13 21 — 5y
0
Also, is the "Owner" object a StringValue, ObjectValue, etc? PoePoeCannon 519 — 5y
0
Look through it again and make sure "Owner" is in that folder, and not in a child of that folder PoePoeCannon 519 — 5y
0
owner is directly is that folder and what is a String or Object Value? Sorry, I'm new KingCheese13 21 — 5y
0
nvm I found it... Object Value KingCheese13 21 — 5y
0
is Owner capitalized? PoePoeCannon 519 — 5y
0
yup KingCheese13 21 — 5y
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. PoePoeCannon 519 — 5y
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 PoePoeCannon 519 — 5y
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. KingCheese13 21 — 5y
0
I tested it and it works great sorry for wasting your time... KingCheese13 21 — 5y
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? PoePoeCannon 519 — 5y
0
of course KingCheese13 21 — 5y
Ad

Answer this question