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

Game pass check? Not when the player enters.

Asked by 9 years ago

I was trying to check if a player has a game pass when they click a gui,but the problem is that i can only check that on roblox server side. Is there some way to check it other then when a player enters?

Module script

local module = {}

local HatPackOne = 223106881
local HatPackTwo = 2

function Authin(player,Pack)
    return game:GetService("GamePassService"):PlayerHasPass(player,Pack)
end

 module.Auth1 = function(player)
    Authin(player,HatPackOne)
end

return module

Script in a gui

local P = game.Players.LocalPlayer
local HatPackOne = 223106881
local HatPackTwo = 2
local Auth = require(game.Workspace.Folder.CheckPass)

function Auth1(Player)
    return game:GetService("GamePassService"):PlayerHasPass(Player,HatPackOne)
end
function Auth2(Player)
        return game:GetService("GamePassService"):PlayerHasPass(Player,HatPackTwo)
end

script.Parent.MouseButton1Click:connect(function()
    if Auth.Auth1(P) then
        print("Player has the pack! Omg! Im so rich!")
    end

end)

1 answer

Log in to vote
0
Answered by 9 years ago

Yep! You can use RemoteFunctions!

In a regular script in Workspace, do this:

local Auth = require(workspace.Folder.CheckPass)
local checkPass = Instance.new("RemoteFunction",workspace)
checkPass.Name = "checkPass"

function checkPass.OnServerInvoke(player,hatpack)
if hatpack == "One" then
    return Auth.hasPackOne(player)
elseif hatpack=="Two" then
    return Auth.hasPackTwo(player)
end
end

Change the module script to this:

local module = {}
local pass = game:GetService("GamePassService")
local HatPackOne = 223106881
local HatPackTwo = 2

function module.Authin(player,Pack)
    return pass:PlayerHasPass(player,Pack)
end

function module.hasPackOne(player)
    return module.Authin(player,HatPackOne)
end

function module.hasPackTwo(player)
    return module.Authin(player,HatPackTwo)
end

return module

And change the local-script to this:

local P = game.Players.LocalPlayer
local hasPackOne = workspace:WaitForChild("checkPass"):InvokeServer("One")
local hasPackTwo= workspace:WaitForChild("checkPass"):InvokeServer("Two")

script.Parent.MouseButton1Click:connect(function()
    if hasPackOne then
        print("Player has the pack! Omg! Im so rich!")
    end
end)

Although the code above is untested; it basically uses remotefunctions to communicate with the server and client.

0
Workspace.Script:7: attempt to call field 'hasPackOne' (a nil value) raspyjessie 117 — 9y
0
Edited DigitalVeer 1473 — 9y
Ad

Answer this question