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

If person buys item then intvalue goes from 0 to 1. If value = 1 then it prints("BYU") How fix?

Asked by 5 years ago
Edited 5 years ago

So I made a shop Gui and whenever you buy an item it changes the text from "Buy!" to purchased. I made the script so that when ever you buy an item it changes the IntValue called Purchase to 1(Meaning they bought it).

local price = script.Parent.Parent.Price
local tools = game.ReplicatedStorage:WaitForChild("Tools")
local tool = tools:FindFirstChild(script.Parent.Parent.ItemNameValue.Value)

local player =  game.Players.LocalPlayer
local cash = player.leaderstats:WaitForChild("Cash")
local Purchased1 = script.Parent.Parent.Parent.Frame.Item1.Purchased
local Purchased2 = script.Parent.Parent.Parent.Frame.Item2.Purchased
local Purchased3 = script.Parent.Parent.Parent.Frame.Item3.Purchased

if script.Parent.Parent.Purchased.Value == 0 then
    print("=0")
    if script.Parent.Parent.Purchased.Value == 1 then
        print("script")
    end
end
script.Parent.MouseButton1Click:Connect(function()
        if cash.Value >= price.Value then
        cash.Value = cash.Value - price.Value
        end
        if price.Value == 100 then
            local oldGun = player.Backpack:FindFirstChildOfClass("Tool") or player.Character:FindFirstChildOfClass("Tool")
            oldGun:Destroy()
            game.ReplicatedStorage.Tools.Pistol:Clone().Parent = player.Backpack
            Purchased1.Value = 1
        end
                if price.Value == 300 then
            local oldGun = player.Backpack:FindFirstChildOfClass("Tool") or player.Character:FindFirstChildOfClass("Tool")
            oldGun:Destroy()
            game.ReplicatedStorage.Tools.Revolver:Clone().Parent = player.Backpack
            Purchased2.Value = 1
                end
                if price.Value == 500 then
            local oldGun = player.Backpack:FindFirstChildOfClass("Tool") or player.Character:FindFirstChildOfClass("Tool")
            oldGun:Destroy()
            game.ReplicatedStorage.Tools.Uzi:Clone().Parent = player.Backpack
            Purchased3.Value = 1
        end
end)

My problem is that when the intvalue == 1 it doesnt print("BYU")

2 answers

Log in to vote
0
Answered by 5 years ago

**Lines 11-16 combat each other, because you're making the script check if the value of "Purchased" if set to 1 when it checked it as 0. ** Whenever the code runs, it checks if the value is 0. If it is, it then checks if it is 1. Separate the two by putting in the following code for lines 11-16:

if script.Parent.Parent.Purchased.Value == 0 then
    print("=0")
elseif script.Parent.Parent.Purchased.Value == 1 then
    print("BYU") -- If it prints "BYU" when the item is bought and it shouldn't do that, just change what is printed in this line. 
end

Hope this works.

0
okthx GunzerkingBeast21 -4 — 5y
0
If it works accept the answer so we know it's done Robloxian_Hero1234 14 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        if game.MarketplaceService:PlayerOwnsAsset(player,ID) then --The id is the id of the gamepass your selling
            SCIPRT HERE -- what you want executed when the player owns the gamepass
        end
    end)
end)

Answer this question