Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

**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.

2 comments

0

okthx

0

If it works accept the answer so we know it's done

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.