Separate your work. Get all the Gui work off of the server. The server should only be responsible for processing the purchase and the client should be responsible for doing anything interface-wise.
For your code, four things: make sure to use GetService to fetch services as it is the canonical way to access services and it helps maintain consistency in your code. As mentioned above too, use functions supported in the engine to do things. GetPlayerByUserId already exists so use that instead of creating your own custom function. Third, old_fog - use a local variable. Don’t know why this exists though.
Now the fourth and most important, to it’s own paragraph: you must reject purchases that are unable to be processed. You have no handler for issues with purchases, such as if the player is not currently in the game, which can be fatal for players and yourself. Unhonoured purchases fall under scamming and will result in the loss of your account. Take percaution and read ProcessReceipt’s documentation.
When it comes to the client showing text, don’t use a remote (cc @return_end1). You’d be generating unnecessary network traffic here. Where possible, try not to use remotes. Here, you will want to use PromptProductPurchaseFinished to determine when the product purchase prompt is closed. Once a player buys your product, you can send the message over.
Applying all this together, you should have two scripts in general. I can give you the code but hopefully you weren’t expecting scripts to be given to you from the start. You never asked a question, just threw a script on your thread and stated what you want. Please confer with our category guidelines in the future when intending to post to this category. This category is not a venue for you to get code written for you, it is to help you help yourself. You need to put the effort into trying to accomplish things on your own by reading API and testing things out.
Server script to handle purchases, should be in ServerScriptService:
-- Run this from the command bar instead, or a different script
game:GetService("StarterGui").ResetPlayerGuiOnSpawn = false
-- camelCase for variables is my preference
local oldFog = game:GetService("Lighting").FogStart
local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
local ServerStorage = game:GetService("ServerStorage")
MarketplaceService.ProcessReceipt = function(receiptInfo)
local productId = receiptInfo.ProductId
local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
if productId == 134468388 then
ServerStorage.Admin:Clone().Parent = player.Backpack
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
LocalScript that sends the personal message, should be in StarterPlayerScripts:
local StarterGui = game:GetService("StarterGui")
local MarketplaceService = game:GetService("MarketplaceService")
local LocalPlayer = game:GetService("Players").LocalPlayer
local MESSAGE_COLOR = BrickColor.new("Dark stone grey").Color
-- I prefer this way of doing my functions nowadays
local function promptProductPurchaseFinished(userId, productId, isPurchased)
-- Confirm all our parameters are correct just in case
if LocalPlayer.UserId == userId and productId == 134468388 and isPurchased == true then
StarterGui:SetCore("ChatMakeSystemMessage", {
Text = "Welcome to the admin side!",
Font = Enum.Font.Cartoon,
FontSize = Enum.FontSize.Size96, -- Don't actually make it 96
Color = MESSAGE_COLOR,
})
end
end)
MarketplaceService.PromptProductPurchaseFinished:Connect(promptProductPurchaseFinished)
Just saying, I don’t recommend using SetCore’s ChatMakeSystemMessage function anymore. Considering the absolute extensiveness of the API and modularisation of the Lua Chat System, realistically you could keep this all server-sided. The Lua Chat System is also standard for working with chat-based necessities. SetCore is can also be unreliable for time and will throw errors if core options aren’t registered.
If you want to do this using the Lua Chat System, get rid of the LocalScript and refer to the Lua Chat System API. What you will need to do is get the speakers of the player and the server (one is created automatically, but you can create one yourself) and then have the server’s speaker send a message to the player’s speaker via the SendMessage method of the ChatSpeaker class.