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

Does this script makes it visible for all other players?

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
 
local gamePassID = 4924584
 
local function onPlayerAdded(player)
 
	local hasPass = false
 
	-- Check if the player already owns the game pass
	local success, message = pcall(function()
		hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
	end)
 
	-- If there's an error, issue a warning and exit the function
	if not success then
		warn("Error while checking if player has pass: " .. tostring(message))
		return
	end
 
	if hasPass == true then
		print(player.Name .. " owns the game pass with ID " .. gamePassID)
		-- Assign this player the ability or bonus related to the game pass
		game.StarterGui.RUN.TextButton.Visible = true
	end

 end
-- Connect 'PlayerAdded' events to the 'onPlayerAdded()' function
Players.PlayerAdded:Connect(onPlayerAdded)




Does this script make the button visible to all other players?

2 answers

✓ Accepted answer

Server Script under ServerScriptService

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local Remote = Instance.new("RemoteEvent")
Remote.Parent = game:GetService("ReplicatedStorage")

local gamePassID = 5923482

game.Players.PlayerAdded:Connect(function(player)
	local hasPass = false

	local success, message = pcall(function()
		hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
	end)

	if not success then
		warn("Error while checking if player has pass: " .. tostring(message))
	else
		if hasPass == false then
			print(player.Name .. " owns the game pass with ID " .. gamePassID)
			Remote:FireClient(player)
		end
	end
end)

Local Script under "RUN"

local Remote = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")

Remote.OnClientEvent:Connect(function()
	script.Parent:WaitForChild("TextButton").Visible = true
end)

Yes, changing the StarterGui would most likely make a player who has a gamepass make this visible to everyone. You can circumvent this using RemoteEvents which will make the activation of the player joining the server make the TextButton visible on that client only (due to FilteringEnabled)

2 comments

0

I don't know why you are spoon feeding he didn't ask for a fix?

0

I already had the script before you closed it, but couldn't post a response

Short answer to this, yes but the changes won't be live until the player resets.

Long answer with solution, So from what I can see you are making a script which checks if the player owns a specific game pass, and if so it enables a Gui object. This can't all be done server sided, you will need to use remote events. You can't see Guis inside PlayerGui from the server as they are completely client sided. Also not only that but every thing which is client sided can be accessed from the client (obviously). So that means that an exploiter can easily run a code to enable the Gui object without having the game pass. It is extremely easy, basically an exploiter can see every Gui object if he'd like to (and everything which is replicated to the client). You better secure that Gui object by doing server sided checks (probably with remote functions)!. So all in all, this can't be done only server sided, you will need to use remote events, make sure you secure the Gui object that is given to the player if the player owns the game pass. Remember, never trust the client.

Articles: http://wiki.roblox.com/index.php?title=Remote_Functions_%26_Events

2 comments

0

lol rep = 666

0

lol

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