So I have a store, there’s an item that the player has to buy, it’s a dumbbell. The item also has an indicator that it should pump, but for some reason, it is equal to nil. BUT, when I tested in the studio all worked, when I restarted also all works, but in some situations does not work. Why?
Local:
-- ПЕРЕМЕННЫЕ
local player = game:GetService("Players").LocalPlayer
local button = player.PlayerGui:WaitForChild("ShopGui").shopMain.buyThingButton2
local equipButton = player.PlayerGui:WaitForChild("ShopGui").shopMain.equipButton2
local character = player.Character
local tool = game:GetService("ReplicatedStorage"):WaitForChild("Tools"):FindFirstChild("Dumbbell3") or player:WaitForChild("Tools"):FindFirstChild("Dumbbell3")
--if tool.Parent == game:GetService("ReplicatedStorage"):WaitForChild("Tools") then
-- button.Visible = true
--elseif tool.Parent == player:WaitForChild("Tools") then
-- button.Visible = false
--end
local ld = player:WaitForChild("leaderstats")
local main = script.Parent.Parent.ShopGui.shopMain
local tween = game:GetService("TweenService")
local buyTool = game:GetService("ReplicatedStorage"):WaitForChild("Remotes").buyTool
local function close()
game:GetService("SoundService").click:Play()
local Info = TweenInfo.new(0.15)
local Tween = tween:Create(main, Info, {Position = UDim2.new(0.205, 0, 1, 0)})
Tween:Play()
game:GetService("Lighting").Blur.Enabled = false
tween:Create(game.Workspace.CurrentCamera, TweenInfo.new(0.2, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {FieldOfView = 70}):Play()
end
local function buy() -- ПОКУПАЕМ ПРЕДМЕТ
if player:WaitForChild("leaderstats").Wins.Value >= 50 then -- ЕСЛИ ДЕНЕГ ХВАТАЕТ
tool.Parent = player:WaitForChild("Tools")
button.Visible = false
player:WaitForChild("leaderstats").Wins.Value -= 50
buyTool:FireServer(tool.Name)
end
end
local function getTool(stat) -- ИЩЕМ ТЕКУЩУЮ ГАНТЕЛЮ
local backpackItems = player.Backpack:GetChildren()
local equipped = player.Character:FindFirstChildOfClass("Tool")
local warehouse = player:WaitForChild("Tools"):GetChildren()
if equipped and equipped.stat.Value == stat then -- ИЩЕМ ПРЕДМЕТ В РУКЕ
return equipped
end
for _, tool in pairs(backpackItems) do -- ИЩЕМ В ИНВЕНТАРЕ
if tool.stat.Value == stat then
return tool
end
end
for _, tool in pairs(warehouse) do -- ИЩЕМ НА СКЛАДЕ
if tool.stat.Value == stat then
return tool
end
end
end
local function equip() -- ЭКИПИРОВЫВАЕМ
local statTool = tool.stat.Value
local currentTool = getTool(statTool)
currentTool.Parent = player:WaitForChild("Tools")
game:GetService("ReplicatedStorage"):WaitForChild("Settings").currentTool.Value = tool.Name
tool.Parent = character
close()
end
-- ВЫЗОВЫ
button.MouseButton1Click:Connect(buy)
--button.TouchTap:Connect(buy)
equipButton.MouseButton1Click:Connect(equip)
--equipButton.TouchTap:Connect(equip)