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

Ignoring if statement help?

Asked by
NotSoNorm 777 Moderation Voter
8 years ago

I have this script that is 'supposed' to work, but if the player doesn't own the gamepass, they still get the gui, what's wrong?

Players = game:GetService("Players")
gps = game:GetService("GamePassService")
id = 266394204 --the gamepass id
VIP = {"Adelenia","NotSoNorm"} --special VIP players
players = game.Players:GetPlayers()

GUI = script.GUI
NewGui = nil
Player = nil
Active = false
Seat = script.Parent

script.Parent.ChildAdded:connect(function(Child)
    print("1pass")
            if Active == false then
                print("2pass")
                if Child.Name == "SeatWeld" then
                    print("3pass")
                    Active = true
                    Player = Players:GetPlayerFromCharacter(Child.Part1.Parent)
                if Child.Parent.Parent.Parent.Name == VIP[1] or VIP[2] or VIP[3] or gps:PlayerHasPass(Player, id) then
                    print("4pass")
                            local PlayerGui = Player:FindFirstChild("PlayerGui")
                        if PlayerGui ~= nil then                
                            NewGui = GUI:Clone()
                            NewGui.Parent = PlayerGui
                            else
                        end
                    end
                end
            end
end)


Seat.ChildRemoved:connect(function(child)
    if child.Name == "SeatWeld" then
        if Active == true then
            Active = false
            local Getchil = script.Parent.Parent.Colors:GetChildren()       
                       for i = 1, #Getchil do
        Getchil[i].BrickColor = BrickColor.new("Navy blue")
        Getchil[i].Material = Enum.Material.Plastic
        end 
            pcall(function() NewGui:Destroy() end)
            Player = nil
            NewGui = nil
        end
    end
end)

1 answer

Log in to vote
1
Answered by
dyler3 1510 Moderation Voter
8 years ago

Your problem is that you're not re-defining each condition in your if statement. You have this:

if Child.Parent.Parent.Parent.Name == VIP[1] or VIP[2] or VIP[3] or gps:PlayerHasPass(Player, id) then

Let me break it down into parts of what this would be doing:

• If Player.Name is Adelenia then continue

or • If there is a second value in the table "VIP" then continue

or • If there is a second value in the table "VIP" then continue

or • If Player has gamepass then continue


So, to fix this, all we need to do is completely re-define each condition before this will work correctly. All you need to do is this:

if Child.Parent.Parent.Parent.Name == VIP[1] or Child.Parent.Parent.Parent.Name == VIP[2] or Child.Parent.Parent.Parent.Name == VIP[3] or gps:PlayerHasPass(Player, id) then

So, let's now insert this into the rest of your script. It will look like this:

Players = game:GetService("Players")
gps = game:GetService("GamePassService")
id = 266394204 --the gamepass id
VIP = {"Adelenia","NotSoNorm"} --special VIP players
players = game.Players:GetPlayers()

GUI = script.GUI
NewGui = nil
Player = nil
Active = false
Seat = script.Parent

script.Parent.ChildAdded:connect(function(Child)
    print("1pass")
            if Active == false then
                print("2pass")
                if Child.Name == "SeatWeld" then
                    print("3pass")
                    Active = true
                    Player = Players:GetPlayerFromCharacter(Child.Part1.Parent)
                if Child.Parent.Parent.Parent.Name == VIP[1] or Child.Parent.Parent.Parent.Name == VIP[2] or Child.Parent.Parent.Parent.Name == VIP[3] or gps:PlayerHasPass(Player, id) then
                    print("4pass")
                            local PlayerGui = Player:FindFirstChild("PlayerGui")
                        if PlayerGui ~= nil then                
                            NewGui = GUI:Clone()
                            NewGui.Parent = PlayerGui
                            else
                        end
                    end
                end
            end
end)


Seat.ChildRemoved:connect(function(child)
    if child.Name == "SeatWeld" then
        if Active == true then
            Active = false
            local Getchil = script.Parent.Parent.Colors:GetChildren()       
                       for i = 1, #Getchil do
        Getchil[i].BrickColor = BrickColor.new("Navy blue")
        Getchil[i].Material = Enum.Material.Plastic
        end 
            pcall(function() NewGui:Destroy() end)
            Player = nil
            NewGui = nil
        end
    end
end)

So basically that was your only problem. Remember that you need to always re-define each condition.

Anyways, if you have any further problems/questions, please leave a comment below. Hope I helped :P

-Dyler3

0
Thanks dude NotSoNorm 777 — 8y
0
No prob. Glad I could help :P dyler3 1510 — 8y
Ad

Answer this question