Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Game pass check? Not when the player enters.

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

✓ Accepted answer

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.

2 comments

0

Workspace.Script:7: attempt to call field 'hasPackOne' (a nil value)

0

Edited

This discussion is preserved as it was. New answers, comments, and votes are closed.