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

My gamepass script won't work?

Asked by
Mr1Vgy 30
9 years ago

Ok so I have this script, and it's supposed to change the text of a gui button if the player has the pass. It's inside a localscript in the PlayerGui inside of a ScreenGui. It won't do anything when I click it. Can anyone help?

id = script.id

function ifPass()
    if game:GetService("GamePassService"):PlayerHasPass(game.Players.LocalPlayer, id.Value)then
        script.Parent.Text = "Equip"
        print('yep')
    elseif not game:GetService("GamePassService"):PlayerHasPass(game.Players.LocalPlayer, id.Value) then
        script.Parent.Text = "Buy"
        print('nope')
    end
end
ifPass()
script.Parent.MouseButton1Click:connect(ifPass)

1 answer

Log in to vote
1
Answered by
yumtaste 476 Moderation Voter
9 years ago

On line 13, you put script.Parent.MouseButton1Click:connect(ifPass). Since this script is in a ScreenGui, and not a TextButton or ImageButton, the event doesn't fire. I took the liberty to rewrite your code for you.

--in TextButton, inside of a ScreenGui

local id = script:FindFirstChild("id")
local GamePassService = game:GetService("GamePassService")
local player = game.Players.LocalPlayer

if GamePassService:PlayerHasPass(player:FindFirstChild("id").Value then
script.Parent.Text = "Equip"
print(player.Name.." has the pass!!")
else
print(player.Name.." doesn't have the pass")
script.Parent.Text = "Buy"
end

This script changes the text of the TextButton depending on whether the player has a pass or not. Make sure you have everything else ready (purchase script, IDs, etc.)

Ad

Answer this question