Basically I’m making a donation board for my game and I’ve made it so that when one of the interactable buttons are clicked the game prompt’s a dev product. But it’s not doing that, infact it seems that the game is not recognizing the player clicking the button at all. I’m getting no error messages, Does anyone know why?
Does it ever print “Donate”? If so at least we know the event is firing on the client but likely not being send/received by the server, if not then you may have an issue with click detection on the part(s) your clicking on preventing the event from even firing locally. Your code “looks like it should run” but something is a miss and chances are it’s related to the event.
From the examples in the documentation for the MarketplaceService, you may need to use both a client and server script if you want to connect it to an event vs just firing it by calling on the function directly.
Pulled from the documentation.
--Client Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local promptPurchaseEvent = ReplicatedStorage:WaitForChild("PromptPurchaseEvent")
local part = Instance.new("Part") --adjust or remove
part.Parent = workspace
local clickDetector = Instance.new("ClickDetector") --adjust or remove
clickDetector.Parent = part
clickDetector.MouseClick:Connect(function() --adjust to miniDonation.MouseButton2Click...
promptPurchaseEvent:FireServer(16630147) --change to ProductId, you only need to specify the product, Player should be handed off to the server with the event, all on it's own.
end)
--Server script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MarketplaceService = game:GetService("MarketplaceService")
local promptPurchaseEvent = Instance.new("RemoteEvent")
promptPurchaseEvent.Name = "PromptPurchaseEvent"
promptPurchaseEvent.Parent = ReplicatedStorage
-- Listen for the RemoteEvent to fire from a Client and then trigger the purchase prompt
promptPurchaseEvent.OnServerEvent:Connect(function(player, id)
MarketplaceService:PromptPurchase(player, id)
end)
What’s not working is that the game is not processing whenever a click the gui I have done some looking around to see what the problem is. Btw I’m using a surface gui with a frame and inside that fram is a textbutton which is where the script is located.
In that case, check your heirachy to verify script.Parent is indeed the textbutton. After that check that there isn’t maybe some sort of Z fighting going on between the button and the rest of the GUI that’s blocking the click.
If it still doesn’t work, as a test create a new button and attach just this script to it, does it work?
-- Place this code in a LocalScript in a TextButton
local textButton = script.Parent
local counter = 0
textButton.Text = "Click me!"
local function onActivated()
counter = counter + 1
textButton.Text = "Clicks: " .. counter
end
textButton.Activated:Connect(onActivated)
Expanded my “StarterGUI” folder, clicked the + beside “ScreenGUI”, added a “TextButton”, clicked the + beside “TextButton”, added a “LocalScript”, pasted the above code (my example, taken from the documentation) into the LocalScript and saved it, pressed Play and clicked the button, each time it incremented.
If it works when setup as above, then the problem lies somewhere in your GUI setup.
If you follow the Interfaces for Parts it almost works for this case except you need to use a TextButton (with the script) vs a TextLabel.
To replicate:
Create a part call it poster, add a SurfaceGUI to it, add a Frame to that, add a TextButton then the script to the TextButton. Tweak values as needed, scale/offset/position. Create another part call it sign then set the posters SurfaceGUI “Adornee” property to the sign. Place the sign in the world. Drag the poster part into the “StarterGUI” folder. Press Play and click the button on the sign to register clicks.
My coffee level is currently below the “I should be posting instructions on the internet” threshold, but I think that should get you going in the right direction.
Is the screenshot provided a LocalScript, or a Script with the RunContext set to Client? Since you’re using a SurfaceGui (which will have a parent in the workspace), a normal LocalScript wouldn’t work. If you haven’t done so already, try moving your code into a regular script and set its RunContext property to Client.
I’ve tested similar code, and this may be your problem.
Yeah, if you have a LocalScript (in a client container) that handles a SurfaceGui under StarterGui and set its Adornee property to a specific part, that would also work.
Though, with no real problems in the code, l figured OP did not have this setup and that this may have been a case where the script was placed in a container where it wouldn’t run. To preserve their setup, what I previously suggested can be a solution, but the adornee route is the more organized one for sure.