Hello, I have a problem when I have 2 tomatoes, pickles it only shows up the one of it.
Here the script:
local Pos = game.Players.LocalPlayer.Inventory.Pos.Value
local Pos2 = game.Players.LocalPlayer.Inventory.Pos
local I1 = UDim2.new(0.148, 0,0.113, 0)
local I2 = UDim2.new(0.567, 0,0113, 0)
local I3 = UDim2.new(0.146, 0,0.522, 0)
local I4 = UDim2.new(0.565, 0,0.522, 0)
local Inventory = game.Players.LocalPlayer.Inventory
local Pickle = Inventory.Prickel
local Tomato = Inventory.Tomato
local Cheese = Inventory.Cheese
local Lettuce = Inventory.Lettuce
local debounce = false
local debounce2 = false
local debounce3 = false
local debounce4 = false
script.Parent.Changed:Connect(function()
if Pos == 1 then
if Tomato.Value >1 then
if debounce == false then
debounce = true
script.Parent.tomato:TweenPosition(I1)
script.Parent.tomato.Visible = true
game.ReplicatedStorage.InvCut:FireServer()
Test()
end
elseif Pickle.Value >1 then
if debounce2 == false then
debounce3 = true
script.Parent.pickle:TweenPosition(I1)
script.Parent.pickle.Visible = true
game.ReplicatedStorage.InvCut:FireServer()
Test()
end
elseif Cheese.Value >1 then
if debounce3 == false then
debounce3 = true
script.Parent.cheese:TweenPosition(I1)
script.Parent.cheese.Visible = true
game.ReplicatedStorage.InvCut:FireServer()
Test()
end
elseif Lettuce.Value >1 then
if debounce4 == false then
debounce4 = true
script.Parent.lettuce:TweenPosition(I1)
script.Parent.lettuce.Visible = true
game.ReplicatedStorage.InvCut:FireServer()
Test()
end
end
end
end)
function Test()
print("2")
wait(0.2)
if Pos2.Value == 2 then
print("22")
if Tomato.Value >1 then
if debounce == false then
debounce = true
script.Parent.tomato:TweenPosition(I2)
script.Parent.tomato.Visible = true
game.ReplicatedStorage.InvCut:FireServer()
end
elseif Pickle.Value >1 then
if debounce2 == false then
debounce3 = true
script.Parent.pickle:TweenPosition(I2)
script.Parent.pickle.Visible = true
game.ReplicatedStorage.InvCut:FireServer()
end
elseif Cheese.Value >1 then
if debounce3 == false then
debounce3 = true
script.Parent.cheese:TweenPosition(I2)
script.Parent.cheese.Visible = true
game.ReplicatedStorage.InvCut:FireServer()
end
elseif Lettuce.Value >1 then
if debounce4 == false then
debounce4 = true
script.Parent.lettuce:TweenPosition(I2)
script.Parent.lettuce.Visible = true
game.ReplicatedStorage.InvCut:FireServer()
end
end
end
end
And here the main script where values get created:
game.Players.PlayerAdded:Connect(function(Player)
print("Giving leaderstats for "..Player.Name)
--Settings
--------------------------------------------
local lead = Instance.new("Folder")
local Cash = Instance.new("IntValue")
local Level = Instance.new("IntValue")
local XP = Instance.new("IntValue")
local Tomato = Instance.new("IntValue")
local Cheese = Instance.new("IntValue")
local Onion = Instance.new("IntValue")
local Prickel = Instance.new("IntValue")
local Lettuce = Instance.new("IntValue")
local Inventory = Instance.new("Folder")
local DataStore = game:GetService("DataStoreService")
local CashSave = DataStore:GetDataStore("CashSave")
local Code1Save = DataStore:GetDataStore("Code1Save")
local Code2Save = DataStore:GetDataStore("Code2Save")
local TomSave = DataStore:GetDataStore("Tomato")
local OnSave = DataStore:GetDataStore("Onion")
local PriSave = DataStore:GetDataStore("Prickel")
local LettSave = DataStore:GetDataStore("Lettuce")
local CodeFolder = Instance.new("Folder")
local Code1 = Instance.new("BoolValue")
local Code2 = Instance.new("BoolValue")
local Pos = Instance.new("IntValue")
--------------------------------------------
--Config
--------------------------------------------
Pos.Value = 1
Pos.Name = "Pos"
Pos.Parent = Inventory
Inventory.Name = "Inventory"
Inventory.Parent = Player
Cheese.Name = "Cheese"
Cheese.Parent = Inventory
Lettuce.Name = "Lettuce"
Lettuce.Parent = Inventory
Prickel.Name = "Prickel"
Prickel.Parent = Inventory
Onion.Name = "Onion"
Onion.Parent = Inventory
Tomato.Name = "Tomato"
Tomato.Parent = Inventory
lead.Parent = Player
Cash.Parent = lead
lead.Name = "leaderstats"
Cash.Name = "Cash"
CodeFolder.Name = "Codes"
CodeFolder.Parent = Player
Code1.Name = "Code1"
Code1.Parent = CodeFolder
Code2.Name = "Code2"
Code2.Parent = CodeFolder
Player.CameraMaxZoomDistance = 100
--------------------------------------------
--Function
--------------------------------------------
Get(Player)
Save(Player)
Cash.Changed:Connect(function()
return Save(Player)
end)
Code1.Changed:Connect(function()
return Save(Player)
end)
Code2.Changed:Connect(function()
return Save(Player)
end)
while wait(10) do
for i, player in pairs(game.Players:GetPlayers()) do
local Cash = player.leaderstats.Cash
Cash.Value = Cash.Value + 100
end
end
--------------------------------------------
end)
game.Players.PlayerRemoving:Connect(function(Player)
Save(Player)
end)
game.ReplicatedStorage.EnterCode.OnServerEvent:Connect(function(Player, reward, code)
CodeHandler(Player, reward, code)
end)
game.ReplicatedStorage.InvCut.OnServerEvent:Connect(function(Player)
Player.Inventory.Pos.Value = Player.Inventory.Pos.Value +1
end)
function Save(Player)
print("Saved for "..Player.Name)
--Settings
--------------------------------------------
local lead = Player.leaderstats
local Cash = lead.Cash
local Code1 = Player.Codes.Code1
local Code2 = Player.Codes.Code2
local Inv = Player.Inventory
local Tomato = Inv.Tomato
local Onion = Inv.Onion
local Prickel = Inv.Prickel
local Lettuce = Inv.Lettuce
local DataStore = game:GetService("DataStoreService")
local CashSave = DataStore:GetDataStore("CashSave")
local Code1Save = DataStore:GetDataStore("Code1Save")
local Code2Save = DataStore:GetDataStore("Code2Save")
local TomSave = DataStore:GetDataStore("Tomato")
local OnSave = DataStore:GetDataStore("Onion")
local PriSave = DataStore:GetDataStore("Prickel")
local LettSave = DataStore:GetDataStore("Lettuce")
local Key = Player.UserId
local SaveCash = CashSave:GetAsync(Key)
local Code1Save = Code1Save:GetAsync(Key)
local Code2Save = Code2Save:GetAsync(Key)
--------------------------------------------
--Config
--------------------------------------------
--N/A
--------------------------------------------
--Function
---------------------------------------------
CashSave:SetAsync(Key, Cash.Value)
TomSave:SetAsync(Key, Tomato.Value)
OnSave:SetAsync(Key, Onion.Value)
PriSave:SetAsync(Key, Prickel.Value)
LettSave:SetAsync(Key, Lettuce.Value)
---------------------------------------------
end
function Get(Player)
print("Got leaderstats for "..Player.Name)
--Settings
--------------------------------------------
local lead = Player.leaderstats
local Cash = lead.Cash
local Code1 = Player.Codes.Code1
local Code2 = Player.Codes.Code2
local Inv = Player.Inventory
local Tomato = Inv.Tomato
local Onion = Inv.Onion
local Prickel = Inv.Prickel
local Lettuce = Inv.Lettuce
local DataStore = game:GetService("DataStoreService")
local CashSave = DataStore:GetDataStore("CashSave")
local Code1Save = DataStore:GetDataStore("Code1Save")
local Code2Save = DataStore:GetDataStore("Code2Save")
local TomSave = DataStore:GetDataStore("Tomato")
local OnSave = DataStore:GetDataStore("Onion")
local PriSave = DataStore:GetDataStore("Prickel")
local LettSave = DataStore:GetDataStore("Lettuce")
local Key = Player.UserId
local SaveCash = CashSave:GetAsync(Key)
local Code1Save = Code1Save:GetAsync(Key)
local Code2Save = Code2Save:GetAsync(Key)
--------------------------------------------
--Config
--------------------------------------------
--N/A
--------------------------------------------
--Function
---------------------------------------------
Cash.Value = SaveCash
Code1.Value = Code1Save
Code2.Value = Code2Save
Tomato.Value = TomSave
Onion.Value = OnSave
Prickel.Value = PriSave
Lettuce.Value = LettSave
--------------------------------------------
end
function CodeHandler(Player, reward, code)
print("Reedemd code for "..Player.Name.." with a reward of "..reward.." and redeemd the code "..code)
--Settings
---------------------------------------------
local lead = Player.Codes
local lead2 = Player.leaderstats
local Cash = lead2.Cash
---------------------------------------------
--Config
----------------------------------------------
--N/A
----------------------------------------------
--Function
----------------------------------------------
Cash.Value = Cash.Value +reward
lead:FindFirstChild(code).Value = true
Save(Player)
----------------------------------------------
end

2 comments
holy
Nobody is going to read that, please only show essential parts if you want the question answered, (btw, having more than 3 datastores is a horrible practice, roblox counts on amount of SetAsyncs, waay less on size, so you can better save everything in a table)