About
Hi! I am making a system where you can buy the ability to collect fruit. What is suppost to happen is when you click an apple a gui will popup and ask you to buy it. But if you close it it wont re open when you click on the apple again. There were no errors.
Apple Collection Script
local CollectionService = game:GetService("CollectionService")
local items = CollectionService:GetTagged("Apple") -- Creates a list with all of the things that you
tagged nameOfTag.
for i, item in ipairs(items) do
-- Code for each item.
local debounce = false
item:WaitForChild("ClickDetector").MouseClick:Connect(function(player)
local ownedCrops = require(player.OwnedCrops)
if ownedCrops.Apples == true then
print("Owned!")
if debounce == false then
debounce = true
local inventoryscript = require(player:WaitForChild("Inventory"))
inventoryscript.Apples = inventoryscript.Apples + 1
player.PlayerGui.Inventory.Main.Frame.ScrollingFrame.Apples.Amount.Text = "x"..inventoryscript.Apples
player.PlayerGui.Sell.Main.Frame.ScrollingFrame.Apples.Amount.Text = "x"..inventoryscript.Apples
print(inventoryscript.Apples)
--Tween
local TweenService = game:GetService("TweenService")
local part = item
local tweenTime = 0.3
local Info = TweenInfo.new(
tweenTime,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out,
0,
false,
0
)
local Goals =
{
Size = Vector3.new(0.1,0.1,0.1),
Transparency = 1,
}
local tween = TweenService:Create(part, Info, Goals)
tween:Play()
wait(tweenTime)
-- End of tween
player.leaderstats.Fruit.Value = player.leaderstats.Fruit.Value + 1
debounce = false
end
wait(math.random(20,40))
--Tween
local TweenService = game:GetService("TweenService")
local part = item
local tweenTime = 0.3
local Info = TweenInfo.new(
tweenTime,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out,
0,
false,
0
)
local Goals =
{
Size = Vector3.new(1.371, 1.474, 1.441),
Transparency = 0,
}
local tween = TweenService:Create(part, Info, Goals)
tween:Play()
wait(tweenTime)
-- End of tween
else
print("Not Owned!")
player.PlayerGui.BuyCrop.Info.Frame.FruitImage.ImageButton.Image = "rbxgameasset://Images/Apple"
player.PlayerGui.BuyCrop.Info.CashAmount.Text = game.ServerStorage.FoodUnlockPrices.Apples.Value.." Cash"
player.PlayerGui.BuyCrop.Opened.Value = true
print(player.PlayerGui.BuyCrop.Opened.Value)
end
end)
end
Local script in the boolvalue called "Opened"
script.Parent:GetPropertyChangedSignal("Value"):Connect(function()
print("Changed")
if script.Parent.Value == true then
print("TRUE")
local TweenService = game:GetService("TweenService")
local gui = script.Parent.Parent.Info
local tweenTime = 0.3
gui.Position = UDim2.new(0.424, 0,1.1, 0)
gui.Visible = true
gui.Parent.Enabled = true
local Info = TweenInfo.new(
tweenTime,
Enum.EasingStyle.Quad,
Enum.EasingDirection.Out,
0,
false,
0
)
local Goals =
{
Position = UDim2.new(0.424, 0,0.337, 0)
}
local tween1 = TweenService:Create(gui, Info, Goals)
tween1:Play()
wait(tweenTime)
-- End of tween
else
print("FALSE")
local TweenService = game:GetService("TweenService")
local gui = script.Parent.Parent.Info
local tweenTime = 0.3
gui.Position = UDim2.new(0.424, 0,0.337, 0)
local Info = TweenInfo.new(
tweenTime,
Enum.EasingStyle.Quad,
Enum.EasingDirection.Out,
0,
false,
0
)
local Goals =
{
Position = UDim2.new(0.424, 0,1.1, 0)
}
local tween2 = TweenService:Create(gui, Info, Goals)
tween2:Play()
wait(tweenTime)
-- End of tween
gui.Visible = false
gui.Parent.Enabled = false
end
end)
Local script in the close button
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
game.ReplicatedStorage.ButtonClick:Play()
local TweenService = game:GetService("TweenService")
local gui = script.Parent.Parent
local tweenTime = 0.1
gui.Position = UDim2.new(0.256, 0,0.841, 0)
gui.Visible = true
local Info = TweenInfo.new(
tweenTime,
Enum.EasingStyle.Bounce,
Enum.EasingDirection.Out,
0,
true,
0
)
local Goals =
{
Position = UDim2.new(0.256, 0,0.854, 0)
}
local tween1 = TweenService:Create(gui, Info, Goals)
tween1:Play()
wait(tweenTime)
script.Parent.Parent.Parent.Parent.Parent.Opened.Value = false
-- End of tween
end)
What prints?
After clicking the apple
After clicking the apple again