Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How Do I Buy From This local Current!?

Asked by
colivs 2
5 years ago

I was provided a code for easier switching for pants and when i attempted to make a buy (as planned) it didn't work, why? (buy code is at the bottom)

local PantsFolder = game.ReplicatedStorage.Clothes.Pants

local ui = game.Players.LocalPlayer.PlayerGui:WaitForChild("Shop")
local PresentModel = workspace:WaitForChild("PresentModel")
local TextLabel = ui.Frame.Pants.PantsName

local Pants = PantsFolder:GetChildren()
local NumPants = #Pants
local upgradeCost = 60
local NextButton = script.Parent.Pants.NextButton
local PreviousButton = script.Parent.Pants.PreviousButton

local Current = 1

local function Update()
    local Pant = PresentModel:FindFirstChildOfClass("Pants")
    if Pant then Pant:Destroy() end

    Pant = Pants[Current]:Clone()
    Pant.Parent = PresentModel

    TextLabel.Text = Pant.Name
end

NextButton.MouseButton1Down:Connect(function()
    Current = Current + 1

    if Current > NumPants then
        Current = 1
    end

    Update()
end)

PreviousButton.MouseButton1Down:Connect(function()
    Current = Current - 1

    if Current <= 0 then
        Current = NumPants
    end

    Update()
end)

local BuyButton = script.Parent.Pants.BuyButton
local player = game.Players.LocalPlayer
local playerStats = player:FindFirstChild("leaderstats")
local playerWallet = playerStats:FindFirstChild("Wallet")

BuyButton.MouseButton1Click:connect(function()
    if Current == 1 then
        if playerWallet.Value < upgradeCost then
    print("Player can't buy")
        else
            if playerWallet.Value >= upgradeCost then
            local character = player.Character
                if character then 
            local pants = character:FindFirstChildOfClass("Pants")
            pants.PantsTemplate = "http://www.roblox.com/asset/?id=8173404"
               end  
            end
        end
    end
end)
0
ScriptingHelpers isn't a request site. SaltyPotter 362 — 5y

1 answer

Log in to vote
0
Answered by
colivs 2
5 years ago

Fixed It.

Ad

Answer this question