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

Gamespass on sit problem?

Asked by
NotSoNorm 777 Moderation Voter
8 years ago

I tried to combine one script with another, and make it so when you sit, it checks if you are a vip and if so it puts a gui in your playergui. It has no errors or anything.

Players = game:GetService("Players")
Workspace = game:GetService("Workspace")
Seat = script.Parent
GUI = script.GUI
Active = false
Player = nil
NewGui = nil
gps = game:GetService("GamePassService");
id =  266394204 --Gamepass ID
VIP = {"Player","NotSoNorm","Adeleina"} --Special Players
players = game.Players:GetPlayers()

Seat.ChildAdded:connect(function(Child)
    for i=1,#VIP do
        for i=1,#players do
            if players[i].Name == VIP[i].Name or gps:PlayerHasPass(players[i], id) then
                    if Active == false then
                if Child.Name == "SeatWeld" then
                    Active = true
                    Player = Players:GetPlayerFromCharacter(Child.Part1.Parent)
                    if Player ~= nil then
                        PlayerGui = Player:FindFirstChild("PlayerGui")
                        if PlayerGui ~= nil then
                            NewGui = GUI:Clone()
                            NewGui.Parent = PlayerGui
                            end
                        end
                    end
                end
            end
        end
    end
end)

1 answer

Log in to vote
0
Answered by 8 years ago

I suggest using a simple debugging technique: add print statements before each 'if' statement to see which condition is failing.

I would also restructure your script a bit:

Players = game:GetService("Players")
Workspace = game:GetService("Workspace")
Seat = script.Parent
GUI = script.GUI
Active = false
gps = game:GetService("GamePassService");
id =  266394204 --Gamepass ID
VIP = {"Player","NotSoNorm","Adeleina"} --Special Players
players = game.Players:GetPlayers()
for i = 1, #VIP do --convert to dictionary for easy lookup
    VIP[VIP[i]] = true
    VIP[i] = nil
end
Seat.ChildAdded:connect(function(Child)
    if Active then return end
    if Child.Name ~= "SeatWeld" then return end
    local player = Players:GetPlayerFromCharacter(Child.Part1.Parent)
    if not player then return end
    if not VIP[player.Name] and not gps:PlayerHasPass(player, id) then return end --not VIP and no access
    PlayerGui = Player:FindFirstChild("PlayerGui")
    if PlayerGui ~= nil then
        local NewGui = GUI:Clone()
        NewGui.Parent = PlayerGui
        Active = true
    end
end)

Notice how I do several checks in the beginning and return from the function if they fail. This prevents you from needing numerous tabs.

Note that this script will only give the GUI to a single person due to the 'Active' variable. You should consider simply checking to see whether the GUI is in the PlayerGui, instead of using 'Active'.

Ad

Answer this question