Toggle speed button

Hey everyone! Can someone help me? :thinking:

What do you want to achieve?

A UI that says “toggle speed” If you own the Double Speed Game Pass you can toggle on to go faster and toggle off to walk around normally. If you don’t own the Game Pass if you click the button you’ll be prompt to purchase it. (Does that make sense?)

What is the issue?
I don’t know how to code this and I can’t hire a scripter.

I can’t find what I’m looking for on YouTube. :neutral_face:

2 Likes

Here are some valuable resources:

Gui = path.to.gui.here  -- e.g. game:GetService("ServerStorage").SpeedGui

local function playerSpeedGui(player)
   local playerOwnsGamepass

   -- find out if the player owns the gamepass
   -- set "playerOwnsGamepass" to whatever it should be

   if playerOwnsGamepass then
      Gui:Clone().Parent = player.PlayerGui
   end
end

game:GetService("Players").PlayerAdded:Connect(function(player)
   -- We need another function here because CharacterAdded gives us
   -- the character and that isn't very helpful when we want to check
   -- if the owner has a gamepass
   player.CharacterAdded:Connect(function()
      playerSpeedGui(player)
   end)
end)

Essentially, what you want to do is:

  • On player spawn, check if player owns the gamepass
  • If they do, show them the walk speed UI
local MarketplaceService = game:GetService('MarketplaceService')
local Player = game:GetService('Players').LocalPlayer
local PassId = 0 -- Gamepass ID
local Button = script.Parent

Button.MouseButton1Click:Connect(function()
    if MarketplaceService:UserOwnsGamePassAsync(Player.UserId,PassId) then -- If they own the gamepass, then
        Player.Character:WaitForChild('Humanoid').WalkSpeed = 20 -- Walkspeed
    else -- Otherwise
        MarketplaceService:PromptGamePassPurchase(Player,PassId) -- Prompts gamepass
    end
end)

Thanks! But I also want to show the GUI even if they don’t have the gamepass.

Well, my code snippet isn’t that hard to edit. You just need to remove the playerOwnsGamepass check and you’re set.

1 Like