How would i implement the
gamepassPurchasedFinished function in this script:
Example
local function gamepassPurchaseFinished(...)
-- Print all the details of the prompt, for example:
-- PromptGamePassPurchaseFinished PlayerName 123456 false
print("PromptGamePassPurchaseFinished", ...)
end
MarketplaceService.PromptGamePassPurchaseFinished:Connect(gamepassPurchaseFinished)
My Script:
local marketplaceservice = game:GetService("MarketplaceService")
local player = game.Players.LocalPlayer
local plrHidden = player:WaitForChild("hiddenstats")
local plrStats = player:WaitForChild("leaderstats")
local boosPassId = 668758510 --replace with your gamepass id
local ts = game:GetService("TweenService")
local info = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut)
local boost1bttn = script.Parent:WaitForChild("CanvasGroup"):WaitForChild("Buttons"):WaitForChild("ToggleBoost"):WaitForChild("ImageButton") -- frame
local boost2bttn = script.Parent:WaitForChild("CanvasGroup"):WaitForChild("Buttons"):WaitForChild("ToggleBoost"):WaitForChild("ImageButton2") -- frame
local delayTimer = .5
local buttonToggled = false
local timeText = script.Parent.CanvasGroup.LeaderstatsFrame.TimeFrame:WaitForChild("TimeText")
local Cash = plrStats:WaitForChild("Cash")
local seconds = plrHidden:WaitForChild("Seconds")
local minutes = plrHidden:WaitForChild("Minutes")
local RS = game:GetService("ReplicatedStorage")
local rent = RS.RemoteEvents:WaitForChild("RentAlert")
local rentGiver = RS.RemoteEvents:WaitForChild("RentGiver")
local sounds = script.Parent.Parent:WaitForChild("Sounds")
local cashSound = sounds:WaitForChild("Cash")
local moneyPlus = script.Parent.CanvasGroup.LeaderstatsFrame.MoneyFrame:WaitForChild("MoneyGiven")
rentGiver.OnClientEvent:Connect(function(money)
Cash.Value = Cash.Value+ money
print("given "..money.." to "..player.Name)
cashSound:Play()
moneyPlus.Text = "+"..money
moneyPlus.Visible = true
ts:Create(moneyPlus, info,{TextTransparency = 1}):Play()
moneyPlus:TweenPosition(UDim2.new(0.3, 0,0, -50), "InOut", "Sine", 1, true)
wait(1)
moneyPlus.Visible = false
ts:Create(moneyPlus, info,{TextTransparency = 0}):Play()
moneyPlus:TweenPosition(UDim2.new(0.3, 0,0, 0), "InOut", "Sine", .1, true)
--print("position restored")
end)
local function MyFunctionName()
wait(delayTimer)
print(delayTimer)
-- the code inside of your while true do function goes here ! because you are repeating the same thing only to change one value "wait(.5)" to "wait(.2)".
timeText.Text = "0"..minutes.Value..":".."0"..seconds.Value
seconds.Value = seconds.Value+1
--print("Second + 1")
if seconds.Value == 60 then
--print("Rent")
rent:FireServer(player)
seconds.Value = 0
minutes.Value = minutes.Value+1
end
if seconds.Value <= 9 and minutes.Value <=9 then
timeText.Text = "0"..minutes.Value..":".."0"..seconds.Value
--print("s & m less than 9")
elseif seconds.Value >= 9 and minutes.Value >=9 then
timeText.Text = minutes.Value..":"..seconds.Value
--print("s & m more than 9")
elseif seconds.Value >= 9 and minutes.Value <=9 then
timeText.Text = "0"..minutes.Value..":"..seconds.Value
--print("s more than 9 m less than 9")
elseif seconds.Value <= 9 and minutes.Value >=9 then
timeText.Text = minutes.Value..":".."0"..seconds.Value
--print("m more than 9 s less than 9")
end
if minutes.Value == 24 then
minutes.Value = 0
seconds.Value = 0
--print("ResetTime")
end
end
boost1bttn.MouseButton1Down:Connect(function()
if marketplaceservice:UserOwnsGamePassAsync(player.UserId,boosPassId) then
delayTimer = .2
boost1bttn.Visible = false
boost2bttn.Visible = true
print(player.Name.." Has the gamepass")
else
marketplaceservice:PromptGamePassPurchase(player,boosPassId)
boost1bttn.Visible = true
boost2bttn.Visible = false
print(player.Name.." Doesn't have the gamepass")
end
buttonToggled = not buttonToggled-- seting it to true if it's false, seting to false if it's true
while not buttonToggled do
MyFunctionName()
end
end)
if boost1bttn.Visible == true then
delayTimer = .5
buttonToggled = not buttonToggled
while buttonToggled do
MyFunctionName()
end
end
boost2bttn.MouseButton1Click:Connect(function()
delayTimer = .5
boost1bttn.Visible = true
boost2bttn.Visible = false
print(player.Name.." is turning off the boost")
buttonToggled = not buttonToggled -- if the button is toggled when
while buttonToggled do
MyFunctionName()
end
end)