iamajust
(iamajust)
February 24, 2021, 7:43pm
#1
Hey developers!
I made this script for a donation board. Though I want to know how to get the player that pressed on this button. Is there any parameter for this? My script:
--Variables--
local buttonlist = script.Parent
local marketplaceSV = game:GetService("MarketplaceService")
--Script--
buttonlist:WaitForChild("5RobuxButton").MouseButton1Click:Connect(function()
marketplaceSV:PromptProductPurchase(?, 1153796205)
end)
buttonlist:WaitForChild("10RobuxButton").MouseButton1Click:Connect(function()
marketplaceSV:PromptProductPurchase(?, 1153796328)
end)
buttonlist:WaitForChild("25RobuxButton").MouseButton1Click:Connect(function()
marketplaceSV:PromptProductPurchase(?, 1153796501)
end)
buttonlist:WaitForChild("50RobuxButton").MouseButton1Click:Connect(function()
marketplaceSV:PromptProductPurchase(?, 1153796703)
end)
buttonlist:WaitForChild("100RobuxButton").MouseButton1Click:Connect(function()
marketplaceSV:PromptProductPurchase(?, 1153797121)
end)
buttonlist:WaitForChild("250RobuxButton").MouseButton1Click:Connect(function()
marketplaceSV:PromptProductPurchase(?, 1153797239)
end)
buttonlist:WaitForChild("500RobuxButton").MouseButton1Click:Connect(function()
marketplaceSV:PromptProductPurchase(?, 1153797321)
end)
buttonlist:WaitForChild("1000RobuxButton").MouseButton1Click:Connect(function()
marketplaceSV:PromptProductPurchase(?, 1153797396)
end)
I know normally you would put this in a LocalScript
in StarterPlayerScripts
, though that doesn’t always fire for me??? Any help would be appreciated!
Have a nice day!
sjr04
(uep)
February 24, 2021, 7:45pm
#2
This is a LocalScript, so you know the local player is Players.LocalPlayer
.
iamajust
(iamajust)
February 24, 2021, 7:46pm
#3
It’s a serversided script
:
sjr04
(uep)
February 24, 2021, 7:46pm
#4
It should be a LocalScript then.
lluckvy
(aaron)
February 24, 2021, 7:47pm
#5
Don’t use server scripts for UI
iamajust
(iamajust)
February 24, 2021, 7:47pm
#6
Again, please read what I said:
lluckvy
(aaron)
February 24, 2021, 7:49pm
#7
Why not just put the local script inside the UI? I’m not really understanding here…
dukzae
(dukzae)
February 24, 2021, 7:49pm
#8
MouseButton1Clicked:Connect(function(player)
end)
2 Likes
GuiButton.MouseButton1Click
doesn’t pass any arguments, you’re thinking of ClickDetector.MouseClick
iamajust
(iamajust)
February 24, 2021, 7:52pm
#10
@sjr04 @lluckvy
This is my LocalScript
. It seems like it doesn’t always fire (already tested with a print):
--Variables--
local buttonlist = game:GetService("Workspace"):WaitForChild("Lobby"):WaitForChild("DonationBoardPart"):WaitForChild("DonationBoardGui")
local localplayer = game:GetService("Players").LocalPlayer
local marketplaceSV = game:GetService("MarketplaceService")
--Script--
buttonlist:WaitForChild("5RobuxButton").MouseButton1Click:Connect(function()
marketplaceSV:PromptProductPurchase(localplayer, 1153796205)
end)
buttonlist:WaitForChild("10RobuxButton").MouseButton1Click:Connect(function()
marketplaceSV:PromptProductPurchase(localplayer, 1153796328)
end)
buttonlist:WaitForChild("25RobuxButton").MouseButton1Click:Connect(function()
marketplaceSV:PromptProductPurchase(localplayer, 1153796501)
end)
buttonlist:WaitForChild("50RobuxButton").MouseButton1Click:Connect(function()
marketplaceSV:PromptProductPurchase(localplayer, 1153796703)
end)
buttonlist:WaitForChild("100RobuxButton").MouseButton1Click:Connect(function()
marketplaceSV:PromptProductPurchase(localplayer, 1153797121)
end)
buttonlist:WaitForChild("250RobuxButton").MouseButton1Click:Connect(function()
marketplaceSV:PromptProductPurchase(localplayer, 1153797239)
end)
buttonlist:WaitForChild("500RobuxButton").MouseButton1Click:Connect(function()
marketplaceSV:PromptProductPurchase(localplayer, 1153797321)
end)
buttonlist:WaitForChild("1000RobuxButton").MouseButton1Click:Connect(function()
marketplaceSV:PromptProductPurchase(localplayer, 1153797396)
end)
iamajust
(iamajust)
February 24, 2021, 7:53pm
#12
It’s a SurfaceGui
. LocalScripts
don’t run in the Workspace
.
sjr04
(uep)
February 24, 2021, 7:53pm
#14
You can put SurfaceGuis in the StarterGui, set the Adornee
of it to the part you want it on, and the localscript will still work
lluckvy
(aaron)
February 24, 2021, 7:54pm
#15
Okay that makes sense, you never specified whether it’s a ScreenGui or SurfaceGui
iamajust
(iamajust)
February 24, 2021, 7:56pm
#16
1 Like
dukzae
(dukzae)
February 24, 2021, 7:56pm
#17
Interesting, I didn’t know that
sjr04
(uep)
February 24, 2021, 7:56pm
#18
You should still parent it to StarterGui, so that the LocalScripts when the Gui is cloned into PlayerGui will run and you can use LocalPlayer
iamajust
(iamajust)
February 24, 2021, 7:56pm
#19
It passes the parameters X
and Y
(the Vector2
position of where the player clicked).
iamajust
(iamajust)
February 24, 2021, 7:57pm
#20
No, I’m fine like this. They already run, they’re in StarterPlayerScripts
.
1 Like
iamajust
(iamajust)
February 24, 2021, 7:59pm
#21
Oop- they do not work anymore. Didn’t change anything though?? Also tried parenting it to StarterGui
, still didn’t work.