Soo a little while back @ForeverHD made this awesome open-sourced Crate/Spin system that is pretty amazing. Latley, I have been playing with this crate system and decided to make it so that in order to spin the crate you must pay 50 Robux per spin. All was good until, I wasn’t able to verify the purchase and make the crate begin.
My Attempted Solutions
- Use a remote event from the local script to server script, then to the module script.
- Remote events don’t work on module scripts
-
_G
global variables- This doesn’t work because global varaibles can only communicate to other scripts under their main parent (e.g. ServerStorage, ServerScriptService)
Some Scripts
Script for where the player clicks the “Spin” button and prompts to pay 50 Robux.
If you want to see the whole script, it’s in the link to the tutorial. This is a local script under StarterGui
--Select Spin
spin.MouseButton1Down:Connect(function()
if spinDe then
spinDe = false
local originalSpinText = spin.TextLabel.Text
-- Purchase is made here
local productId = 574458039
game:GetService("MarketplaceService"):PromptProductPurchase(game.Players.LocalPlayer, productId)
-- Checks to see if player has permission (Function sent from the module script)
if not contents:PermissionToSpin(player) then
spin.TextLabel.Text = contents.Messages.FailPermissionCheck
wait(1)
else
spin.TextLabel.Text = contents.Messages.Loading
local spinDetails, errorMessage = rfunction:InvokeServer()
if not spinDetails then
if not errorMessage then
errorMessage = contents.Messages.ServerError
end
spin.TextLabel.Text = errorMessage
wait(1)
else
SpinFunction(spinDetails)
end
end
spin.TextLabel.Text = originalSpinText
spinDe = true
end
end)
Here is the Module script with the value that needs to be set to “true” upon purchase.
-- << Permission to Spin >>
function contents:PermissionToSpin(player)
-- Here is the purchase was made it would be set to "return true"
end
Ultimate Goal
- Player Clicks “Spin”
- Prompts player to spend 50 robux
- If spends the 50 robux, the module script would return true.
- The crate appears and player claims prize
- Redo the proccess