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

Changing Teams with gamepasses?

Asked by 7 years ago
Edited 7 years ago

Hello everyone,

I've recently began working on my own game which has resulted in multiple errors. I'm used to working with C# and since Roblox used Lua. Well yea... I've looked through multiple forums, tutorials and a little bit on this website for a solution to my problem. I'm trying to make a player change teams when pressing a button on a gui whilst checking the gamepass. As gamepassservice requires the script to be server sided I can't use a localscript. In the Roblox studio this code works but when I go in-game and I press the gui it doesn't.

This is my script:

local gamepassID = ******

script.Parent.MouseButton1Click:connect(function (playerWhoClicked)
    local player = game.Players.LocalPlayer
    local gps = game:GetService("GamePassService")
    local playerHasPass = gps:PlayerHasPass(player, gamepassID)

    if playerHasPass then
        player.Team = game.Teams.HATO
    else
        gps:PromptPurchase(player, gamepassID)
    end
end)

Kind regards,

SamDeNormaleAap

2 answers

Log in to vote
0
Answered by 7 years ago
if playerHasPass then
        player.Team.Name = "HATO"
Ad
Log in to vote
0
Answered by 3 years ago

use/try this:

local gamepassID = ******

script.Parent.MouseButton1Click:connect(function (playerWhoClicked)
    local player = game.Players.LocalPlayer
    local gps = game:GetService("GamePassService")
    local playerHasPass = gps:PlayerHasPass(player, gamepassID)

    if playerHasPass then
          player.Team.Name = "HATO"
    else
        gps:PromptPurchase(player, gamepassID)
    end
end)

I think is work

Answer this question