So, I was working on a simulator until a came across a really annoying bug. For some reason, the script thinks that multiple items are equipped, when they are not? Can anyone help me with this. Here is my script btw:
local foodFolder = game.ReplicatedStorage.Food
local foodOrder = {foodFolder.Banana, foodFolder.Chicken}
local screenGui = script.Parent
local frame = screenGui.Frame
local purchase = frame.Purchase
local back = frame.Back
local itemName = frame.ItemName
local price = frame.Price
local blackScreen = screenGui.BlackScreen
local nxt = frame.Next
local prev = frame.Previous
local fadeIn = game:GetService("TweenService"):Create(blackScreen, TweenInfo.new(.5), {Transparency = 0})
local fadeOut = game:GetService("TweenService"):Create(blackScreen, TweenInfo.new(1), {Transparency = 1})
local shopTeleport = workspace.ShopTeleport
local camera = workspace.CurrentCamera
local currentIndex = 1
function find(player)
for _, equippedFood in pairs(player.Backpack:GetChildren()) do
return equippedFood
end
for _, item in pairs(player.Character:GetChildren()) do
if item:IsA("Tool") then
return item
end
end
end
function add(by)
currentIndex = currentIndex + by
return
end
local shopOpen = false
game.ReplicatedStorage.ShopManipulation.OnClientEvent:Connect(function()
local thing = find(game.Players.LocalPlayer)
if thing then
thing.Name = game.Players.LocalPlayer.Name
thing.Parent = game.ReplicatedStorage
end
if shopOpen == false then
shopOpen = true
game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = shopTeleport.CFrame + Vector3.new(0, 3, 0)
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 0
game.Players.LocalPlayer.Character.Humanoid.JumpPower = 0
blackScreen.Visible = true
screenGui.Enabled = true
fadeIn:Play()
wait(.5)
camera.CameraType = "Scriptable"
camera.CFrame = workspace.Shop.CameraPoints:FindFirstChild(foodOrder[1].Name).CFrame
frame.Visible = true
local foodName = foodOrder[1].Name
itemName.Text = foodOrder[1].Name
price.Text = "$"..foodFolder:FindFirstChild(foodName).Price.Value
wait(3)
fadeOut:Play()
back.MouseButton1Click:Connect(function()
screenGui.Enabled = false
camera.CameraType = "Custom"
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16
game.Players.LocalPlayer.Character.Humanoid.JumpPower = 50
if not find(game.Players.LocalPlayer) then
game.ReplicatedStorage:FindFirstChild(game.Players.LocalPlayer.Name).Parent = game.Players.LocalPlayer.Backpack
end
shopOpen = false
return
end)
nxt.MouseButton1Click:Connect(function()
add(1)
if currentIndex > #foodOrder then
currentIndex = 1
foodName = foodOrder[currentIndex].Name
else
foodName = foodOrder[currentIndex].Name
end
if game.Players.LocalPlayer.OwnedFood:FindFirstChild(foodOrder[currentIndex].Name) then
if game.Players.LocalPlayer.Equipped.Value == foodOrder[currentIndex].Name then
purchase.Text = "Equipped"
purchase.TextButton_Roundify_12px.ImageColor3 = Color3.fromRGB(23, 135, 255)
else
purchase.Text = "Equip"
purchase.TextButton_Roundify_12px.ImageColor3 = Color3.fromRGB(23, 135, 255)
end
else
purchase.Text = "Purchase"
purchase.TextButton_Roundify_12px.ImageColor3 = Color3.fromRGB(50, 255, 14)
end
itemName.Text = foodName
price.Text = "$"..foodFolder:FindFirstChild(foodName).Price.Value
local tween = game:GetService("TweenService"):Create(camera, TweenInfo.new(1), {CFrame = workspace.Shop.CameraPoints:FindFirstChild(foodName).CFrame})
tween:Play()
end)
prev.MouseButton1Click:Connect(function()
add(-1)
if currentIndex < 1 then
currentIndex = #foodOrder
foodName = foodOrder[currentIndex].Name
else
foodName = foodOrder[currentIndex].Name
end
if game.Players.LocalPlayer.OwnedFood:FindFirstChild(foodOrder[currentIndex].Name) then
if game.Players.LocalPlayer.Equipped.Value == foodOrder[currentIndex].Name then
purchase.Text = "Equipped"
purchase.TextButton_Roundify_12px.ImageColor3 = Color3.fromRGB(23, 135, 255)
else
purchase.Text = "Equip"
purchase.TextButton_Roundify_12px.ImageColor3 = Color3.fromRGB(23, 135, 255)
end
else
purchase.Text = "Purchase"
purchase.TextButton_Roundify_12px.ImageColor3 = Color3.fromRGB(50, 255, 14)
end
itemName.Text = foodName
price.Text = "$"..foodFolder:FindFirstChild(foodName).Price.Value
local tween = game:GetService("TweenService"):Create(camera, TweenInfo.new(1), {CFrame = workspace.Shop.CameraPoints:FindFirstChild(foodName).CFrame})
tween:Play()
end)
spawn(function()
while wait() do
local thing = find(game.Players.LocalPlayer)
if thing and thing.Name ~= game.Players.LocalPlayer.Equipped.Value and shopOpen then
thing:Destroy()
end
end
end)
purchase.MouseButton1Click:Connect(function()
if not game.Players.LocalPlayer.OwnedFood:FindFirstChild(foodName) and game.Players.LocalPlayer.leaderstats.Cash.Value >= foodFolder:FindFirstChild(foodName).Price.Value then
frame.Purchased:Play()
game.ReplicatedStorage.PurchaseFood:FireServer(foodName, foodFolder:FindFirstChild(foodName).Price.Value)
purchase.Text = "Equip"
purchase.TextButton_Roundify_12px.ImageColor3 = Color3.fromRGB(23, 135, 255)
elseif game.Players.LocalPlayer.OwnedFood:FindFirstChild(foodName) then
if game.Players.LocalPlayer.Equipped.Value == foodName then
-- Unequip
for i, v in pairs(game.Players.LocalPlayer.Backpack:GetChildren()) do
print(v.Name)
end
game.Players.LocalPlayer.Backpack:FindFirstChild(foodName):Destroy()
game.Players.LocalPlayer.Equipped.Value = ""
purchase.Text = "Equip"
else
-- Equip
game.ReplicatedStorage.Food:FindFirstChild(foodName):Clone().Parent = game.Players.LocalPlayer.Backpack
game.Players.LocalPlayer.Equipped.Value = foodName
purchase.Text = "Equipped"
end
end
end)
end
end)
Hopefully somebody can help!