I have some game passes in my game. I have a local script which checks if the player has the gamepass. If they do, then the local script makes the text button visible.
Here is the local script (inside text button):
local Player = game.Players.LocalPlayer local WalkSpeedId = My GamePass Id local MarketPlaceService = game:GetService("MarketplaceService") if MarketPlaceService:UserOwnsGamePassAsync(Player.UserId, WalkSpeedId) then script.Parent.Visible = true else script.Parent.Visible = false end
Is this a good way to do it? Can hackers change this so that even if they don't have the gamepass, they can still make the gui visible? Can I use remote events here? If yes, then how.
Any help would be appreciated.
Answer: Use remote events and check for the gamepass in server. Step 1: Add a remote event in ReplicatedStorage. Step 2: Add a server script in ServerScriptService. Step 3: Write this in the server script:
local MarketplaceService = game:GetService("MarketplaceService") local WalkSpeedId = (gamepass id here) local RemoteEvent = game.ReplicatedStorage:WaitForChild("RemoteEvent") game.Players.PlayerAdded:Connect(function(player) RemoteEvent:FireClient(player, MarketplaceService:UserOwnsGamePassAsync(player.UserId, WalkSpeedId) end)
Step 4: Write this in the local script in a text button:
local RemoteEvent = game.ReplicatedStorage:WaitForChild("RemoteEvent") RemoteEvent.OnClientEvent:Connect(function(bool) script.Parent.Visible = bool shouldBeVisible = bool end)
Step 5: Do a while true do
loop in the server script's PlayerAdded
function to fire to the client about the visibility of the TextButton:
game.Players.PlayerAdded:Connect(function(player) -- replace the `:FireClient()` with a `while true do` loop firing to the client about the client's visibility while true do RemoteEvent:FireClient(player, MarketplaceService:UserOwnsGamePassAsync(player.UserId, WalkSpeedId) wait(2) end end)
Explanations: This is for exploit-proofing. Do the check in the server and fire it to the client in regular intervals to prevent exploiters from opening the TextButton and to annoy them into not opening it anymore (strategy may not work). Hope this helps!
Is this a good way to do it? This way is absolutely fine, HOWEVER checking if they own the gamepass on the server would prevent some exploiters. (Use remote events!)
Can hackers change this so that even if they don't have the gamepass, they can still make the gui visible? Yes most definitely, you cannot stop this though.
Can I use remote events here? See answer 1.
If yes, then how?
Make a remote event in ReplicatedStorage, fire it from the server to the client using :FireClient(player)
.
See more here.