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

Giving someone a game-pass from the script?

Asked by 5 years ago
*How do I give my Co-Owner ("Team create person") a game-pass without them buying it?

I tried this:*

permission = { "PLAYERS NAME HERE" } -- My buddy's name



local function WaitForChild(parent, childName)
    assert(parent, "ERROR: WaitForChild: parent is nil")
    while not parent:FindFirstChild(childName) do parent.ChildAdded:wait() end
    return parent[childName]
end



local GamePassService = game:GetService('MarketplaceService')
local PlayersService = game:GetService('Players')

local VipDoor = script.Parent

local GamePassIdObject = script:WaitForChild( 'GamePassId')

local JustTouched = {}




local function TeleportToOtherSide(character, hitPart)
    local bottomOfDoor = VipDoor.CFrame.p - Vector3.new(0, VipDoor.Size.Y / 2, 0)
    local inFrontOfDoor = bottomOfDoor + VipDoor.CFrame.lookVector * 3
    local behindDoor = bottomOfDoor - VipDoor.CFrame.lookVector * 3

    local distanceToFront = (inFrontOfDoor - hitPart.Position).magnitude
    local distanceToBack = (behindDoor - hitPart.Position).magnitude
    if distanceToFront < distanceToBack then
        character:MoveTo(behindDoor)
    else
        character:MoveTo(inFrontOfDoor)
    end
end


local function OnTouched(otherPart)
    if otherPart and otherPart.Parent and otherPart.Parent:FindFirstChild('Humanoid') then
        local player = PlayersService:GetPlayerFromCharacter(otherPart.Parent)
        if player and not JustTouched[player] then
            JustTouched[player] = time()
            if GamePassService:UserOwnsGamePassAsync(player.userId, GamePassIdObject.Value) then
                TeleportToOtherSide(player.Character, otherPart)
            end
        end
    end
end


local function RemoveOldTouches()
    for player, touchTime in pairs(JustTouched) do
        if time() > touchTime + 0.3 then
            JustTouched[player] = nil
        end
    end
end



VipDoor.Touched:connect(OnTouched)

while true do
    RemoveOldTouches()
    wait(1/30)
end

I need help!``

0
You could just do an or player.Name == on line 45 if you're only going to use this for 1 person, theres no point making a table. DinozCreates 1070 — 5y

1 answer

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

On line 45, you can add your friends name to the if statement. Here's what I mean:

if GamePassService:UserOwnsGamePassAsync(player.userId, GamePassIdObject.Value) or player.Name == "NameHere" then
    TeleportToOtherSide(player.Character, otherPart)
end

However, using a player's name isn't the best thing to do because players can change their name and it'd no longer work. Instead, you can use their UserID:

if GamePassService:UserOwnsGamePassAsync(player.userId, GamePassIdObject.Value) or player.UserId == 12345 then
    TeleportToOtherSide(player.Character, otherPart)
end

There are other ways to do this, I'd just thought that this would be the easiest way for you. Also, you should use tab to indent your scripts instead of space. One more thing, make sure to use :Connect() instead of :connect() which is deprecated.

0
Thanks for doing what i was too lazy to do. DinozCreates 1070 — 5y
0
player.UserId takes in a integer not a string User#23365 30 — 5y
0
Thank you everyone : ) xXnutcrakerXx -10 — 5y
0
My bad, missed that. Fixed Crazycat4360 115 — 5y
View all comments (3 more)
0
xd i had it wrong xXnutcrakerXx -10 — 5y
0
Wait, is "or" (inside the script you gave me) part of the script or not?. xXnutcrakerXx -10 — 5y
0
can you please send me the full script? xXnutcrakerXx -10 — 5y
Ad

Answer this question