I made a donate board at spawn, it have surface gui, 8 buttons, now how do I detect the player who clicked these buttons? and then give him purchase?
By using a RemoteEvent.
--LOCAL SCRIPT--
local part = workspace:WaitForChild("Part")
local surfaceGui = part:WaitForChild("SurfaceGui")
local frame = surfaceGui:WaitForChild("Frame")
local button = frame:WaitForChild("TextButton")
local storage = game:GetService("ReplicatedStorage")
local remote = storage:WaitForChild("RemoteEvent")
button.MouseButton1Click:Connect(function()
remote:FireServer()
end)
--SERVER SCRIPT--
local MPService = game:GetService("MarketplaceService")
local storage = game:GetService("ReplicatedStorage")
local remote = storage:WaitForChild("RemoteEvent")
local gamepassId = 0 --change to gamepass id
remote.OnServerEvent:Connect(function(player)
MPService:PromptGamePassPurchase(player, gamepassId)
end)
Organisation:
--SERVER SCRIPT--
local surfaceGui = script.Parent.Parent
local frame = script.Parent.Parent
local button = script.Parent
local storage = game:GetService("ReplicatedStorage")
local remote = storage:WaitForChild("RemoteEvent")
button.MouseButton1Click:Connect(function()
remote:FireServer()
end)
You need to fire client, how do I get the cilent? also isnt it fire client?
My bad, I had the labels the wrong way around. I was writing both scripts inside the same script, excuse that. I’ve edited the original reply.