Advertisement
HowToRoblox

MiningSimulatorClient

Nov 24th, 2022
701
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 12.68 KB | None | 0 0
  1. local rs = game.ReplicatedStorage:WaitForChild("MiningSimulatorReplicatedStorage")
  2. local re = rs:WaitForChild("RemoteEvent")
  3.  
  4. local pickaxes = rs:WaitForChild("Pickaxes")
  5. local backpacks = rs:WaitForChild("Backpacks")
  6.  
  7. local moduleScripts = rs:WaitForChild("CONFIGURATION")
  8. local stonesConfig = require(moduleScripts:WaitForChild("Stones"))
  9. local oresConfig = require(moduleScripts:WaitForChild("Ores"))
  10. local pickaxesConfig = require(moduleScripts:WaitForChild("Pickaxes"))
  11. local backpacksConfig = require(moduleScripts:WaitForChild("Backpacks"))
  12. local otherConfig = require(moduleScripts:WaitForChild("OtherSettings"))
  13.  
  14. local guiTemplates = rs:WaitForChild("GuiTemplates")
  15. local displayModelPositions = rs:WaitForChild("DisplayModelPositions")
  16.  
  17. local areas = workspace:WaitForChild("MiningSimulatorAreas")
  18.  
  19.  
  20. local client = game.Players.LocalPlayer
  21. local char = script.Parent
  22. local mouse = client:GetMouse()
  23.  
  24. local backpack = client:WaitForChild("Backpack")
  25.  
  26. local pickaxeValue = client:WaitForChild("Equipment"):WaitForChild("Pickaxe")
  27. local backpackValue = client:WaitForChild("Equipment"):WaitForChild("Backpack")
  28.  
  29. local backpackContents = client:WaitForChild("BackpackContents")
  30.  
  31. local plrGui = client:WaitForChild("PlayerGui")
  32. local oreGui = plrGui:WaitForChild("OreGui")
  33. local backpackGui = plrGui:WaitForChild("BackpackGui")
  34. local shopGui = plrGui:WaitForChild("ShopGui")
  35. local surfaceGui = plrGui:WaitForChild("TpToSurfaceGui")
  36. local failedDataWarning = plrGui:WaitForChild("FailedToLoadDataWarning")
  37. oreGui.Enabled, shopGui.Enabled, failedDataWarning.Enabled, backpackGui.Enabled, surfaceGui.Enabled = false, false, false, true, true
  38.  
  39.  
  40. --Backpack Gui
  41. function updateBackpackGui()
  42.     repeat
  43.         task.wait(0.1)
  44.     until backpackValue.Value ~= nil
  45.    
  46.     local backpackStorage = backpacksConfig[backpackValue.Value].storage
  47.    
  48.     local totalBackpackContents = 0
  49.     for i, oreValue in pairs(backpackContents:GetChildren()) do
  50.         totalBackpackContents += oreValue.Value
  51.     end
  52.    
  53.     local yScale = totalBackpackContents / backpackStorage
  54.     backpackGui.BarBG.Bar:TweenSize(UDim2.new(1, 0, yScale, 0), "InOut", "Linear", 0.3)
  55.    
  56.     backpackGui.BarBG.CurrentBackpackFill.Text = totalBackpackContents .. "/" .. backpackStorage
  57.     backpackGui.BarBG.CurrentBackpackFill.Position = UDim2.new(2.92, 0, 1 - yScale, 0)
  58. end
  59. updateBackpackGui()
  60. for ore, config in pairs(oresConfig) do
  61.     local oreValue = backpackContents:WaitForChild(ore)
  62.     oreValue:GetPropertyChangedSignal("Value"):Connect(updateBackpackGui)
  63. end
  64. for ore, config in pairs(stonesConfig) do
  65.     local oreValue = backpackContents:WaitForChild(ore)
  66.     oreValue:GetPropertyChangedSignal("Value"):Connect(updateBackpackGui)
  67. end
  68. backpackValue:GetPropertyChangedSignal("Value"):Connect(updateBackpackGui)
  69.  
  70.  
  71. --Hovering over ores
  72. local currentSelectionBox = nil
  73.  
  74. game:GetService("RunService").Heartbeat:Connect(function()
  75.     mouse.TargetFilter = areas:WaitForChild("OreZone")
  76.     local target = mouse.Target
  77.    
  78.     local pickaxe = char:FindFirstChildOfClass("Tool")
  79.    
  80.     if target and target.Parent == workspace:WaitForChild("SPAWNED ORES FOLDER") and (char.HumanoidRootPart.Position - target.Position).Magnitude <= otherConfig.MaxOreRange and pickaxe and pickaxe.Name == pickaxeValue.Value then
  81.        
  82.         if not currentSelectionBox or currentSelectionBox.Parent == nil then
  83.             currentSelectionBox = Instance.new("SelectionBox")
  84.         end
  85.         currentSelectionBox.Adornee = target
  86.         currentSelectionBox.Parent = target
  87.                
  88.         local oreName = target.Name
  89.         local oreHealth = target.HEALTH.Value
  90.         local oreMaxHealth = oresConfig[oreName] and oresConfig[oreName].health or stonesConfig[oreName].health
  91.            
  92.         oreGui.BarBG.OreName.Text = oreName
  93.         oreGui.BarBG.CurrentHealth.Text = oreHealth .. "/" .. oreMaxHealth
  94.                
  95.         local xScale = oreHealth / oreMaxHealth
  96.         if oreHealth < oreMaxHealth then
  97.             oreGui.BarBG.Bar:TweenSize(UDim2.new(xScale, 0, 1, 0), "InOut", "Linear", 0.3)
  98.         else
  99.             oreGui.BarBG.Bar.Size = UDim2.new(xScale, 0, 1, 0)
  100.         end
  101.                
  102.         oreGui.Enabled = true
  103.  
  104.     elseif currentSelectionBox then
  105.         currentSelectionBox:Destroy()
  106.         oreGui.Enabled = false
  107.     end
  108. end)
  109.  
  110.  
  111. --Clicking on ores
  112. mouse.Button1Up:Connect(function()
  113.     mouse.TargetFilter = areas:WaitForChild("OreZone")
  114.    
  115.     local pickaxe = char:FindFirstChild(pickaxeValue.Value)
  116.     if pickaxe then
  117.        
  118.         local target = mouse.Target
  119.         if target and target.Parent == workspace:WaitForChild("SPAWNED ORES FOLDER") then
  120.            
  121.             re:FireServer("MINE ORE", {target})
  122.         end
  123.     end
  124. end)
  125.  
  126.  
  127. --SHOPS
  128. local currentShop = nil
  129.  
  130.  
  131. function displayItem(itemName)
  132.     local item = pickaxes:FindFirstChild(itemName) or backpacks:FindFirstChild(itemName)
  133.    
  134.     if currentShop and item then
  135.        
  136.         shopGui.ItemName.Text = itemName
  137.        
  138.         local vpf = shopGui.ItemViewer
  139.         vpf:ClearAllChildren()
  140.        
  141.         local vpfCam = Instance.new("Camera")
  142.         vpf.CurrentCamera = vpfCam
  143.         vpfCam.Parent = vpf
  144.        
  145.         local displayModel = Instance.new("Model")
  146.         displayModel.Parent = vpf
  147.        
  148.         for i, descendant in pairs(item:GetDescendants()) do
  149.             if descendant:IsA("BasePart") then
  150.                 local clonedPart = descendant:Clone()
  151.                 clonedPart.Parent = displayModel
  152.             end
  153.         end
  154.         displayModel.PrimaryPart =
  155.             displayModel:FindFirstChild(displayModelPositions.Pickaxe.PrimaryPart.Name)
  156.             or displayModel:FindFirstChild(displayModelPositions.Backpack.PrimaryPart.Name)
  157.             or displayModel:FindFirstChild("Handle")
  158.             or displayModel:FindFirstChild("RootAttachment")
  159.             or displayModel:FindFirstChildOfClass("BasePart")
  160.        
  161.         displayModel:SetPrimaryPartCFrame(
  162.                 displayModelPositions.Pickaxe:FindFirstChild(displayModel.PrimaryPart.Name) and displayModelPositions.Pickaxe.PrimaryPart.CFrame
  163.                 or displayModelPositions.Backpack:FindFirstChild(displayModel.PrimaryPart.Name) and displayModelPositions.Backpack.PrimaryPart.CFrame
  164.                 or CFrame.new(0, 0, -10)
  165.         )
  166.         vpfCam.CFrame = displayModelPositions.Pickaxe:FindFirstChild(displayModel.PrimaryPart.Name) and displayModelPositions.Pickaxe["CAMERA REFERENCE"].CFrame
  167.             or displayModelPositions.Backpack:FindFirstChild(displayModel.PrimaryPart.Name) and displayModelPositions.Backpack["CAMERA REFERENCE"].CFrame
  168.             or CFrame.new(0, 0, 0)
  169.        
  170.         if itemName == pickaxeValue.Value or itemName == backpackValue.Value then
  171.             shopGui.BuyButton.Text = "Using"
  172.             shopGui.BuyButton.BackgroundColor3 = Color3.fromRGB(58, 134, 54)
  173.         else
  174.             shopGui.BuyButton.Text = "Buy for $" .. (pickaxesConfig[itemName] and pickaxesConfig[itemName].cost or backpacksConfig[itemName].cost)
  175.             shopGui.BuyButton.BackgroundColor3 = Color3.fromRGB(64, 208, 86)
  176.         end
  177.            
  178.         for i, child in pairs(shopGui.StatsFrame.StatsContainer:GetChildren()) do
  179.             if child:IsA("Frame") then
  180.                 child:Destroy()
  181.             end
  182.         end
  183.        
  184.         if currentShop == "PICKAXE" then
  185.             local damageStat = guiTemplates:WaitForChild("StatisticFrame"):Clone()
  186.             damageStat.StatisticName.Text = "Damage:"
  187.             damageStat.StatisticValue.Text = pickaxesConfig[itemName].damage
  188.             damageStat.Parent = shopGui.StatsFrame.StatsContainer
  189.            
  190.             local multiplierStat = guiTemplates:WaitForChild("StatisticFrame"):Clone()
  191.             multiplierStat.StatisticName.Text = "Multiplier:"
  192.             multiplierStat.StatisticValue.Text = "x" .. pickaxesConfig[itemName].multiplier
  193.             multiplierStat.Parent = shopGui.StatsFrame.StatsContainer
  194.            
  195.             local cooldownStat = guiTemplates:WaitForChild("StatisticFrame"):Clone()
  196.             cooldownStat.StatisticName.Text = "Cooldown:"
  197.             cooldownStat.StatisticValue.Text = pickaxesConfig[itemName].cooldown .. "s"
  198.             cooldownStat.Parent = shopGui.StatsFrame.StatsContainer
  199.            
  200.         elseif currentShop == "BACKPACK" then
  201.             local storageStat = guiTemplates:WaitForChild("StatisticFrame"):Clone()
  202.             storageStat.StatisticName.Text = "Storage:"
  203.             storageStat.StatisticValue.Text = backpacksConfig[itemName].storage .. " ores"
  204.             storageStat.Parent = shopGui.StatsFrame.StatsContainer
  205.         end
  206.     end
  207. end
  208.  
  209.  
  210. shopGui.ExitButton.MouseButton1Click:Connect(function()
  211.     shopGui.Enabled = false
  212. end)
  213.  
  214. shopGui.BuyButton.MouseButton1Click:Connect(function()
  215.    
  216.     if currentShop then
  217.         local selectedItem = shopGui.ItemName.Text
  218.         if selectedItem ~= pickaxeValue.Value and selectedItem ~= backpackValue.Value then
  219.            
  220.             if client.leaderstats.Cash.Value >= (pickaxesConfig[selectedItem] and pickaxesConfig[selectedItem].cost or backpacksConfig[selectedItem].cost) then
  221.                 re:FireServer("BUY " .. currentShop, {selectedItem})
  222.             end
  223.         end
  224.     end
  225. end)
  226.  
  227. shopGui.LeftButton.MouseButton1Click:Connect(function()
  228.    
  229.     local currentItem = shopGui.ItemName.Text
  230.    
  231.     if currentShop == "PICKAXE" then
  232.        
  233.         local pickaxesByPrice = {}
  234.         for pickaxe, config in pairs(pickaxesConfig) do
  235.            
  236.             if config.cost > 0 then
  237.                 table.insert(pickaxesByPrice, pickaxe)
  238.             end
  239.         end
  240.        
  241.         table.sort(pickaxesByPrice, function(a, b)
  242.             return pickaxesConfig[a].cost < pickaxesConfig[b].cost
  243.         end)
  244.        
  245.         local currentIndex = table.find(pickaxesByPrice, currentItem)
  246.         if currentIndex and currentIndex > 1 then
  247.             local newIndex = currentIndex - 1
  248.            
  249.             displayItem(pickaxesByPrice[newIndex])
  250.         end
  251.        
  252.     elseif currentShop == "BACKPACK" then
  253.  
  254.         local backpacksByPrice = {}
  255.         for backpack, config in pairs(backpacksConfig) do
  256.  
  257.             if config.cost > 0 then
  258.                 table.insert(backpacksByPrice, backpack)
  259.             end
  260.         end
  261.  
  262.         table.sort(backpacksByPrice, function(a, b)
  263.             return backpacksConfig[a].cost < backpacksConfig[b].cost
  264.         end)
  265.  
  266.         local currentIndex = table.find(backpacksByPrice, currentItem)
  267.         if currentIndex and currentIndex > 1 then
  268.             local newIndex = currentIndex - 1
  269.  
  270.             displayItem(backpacksByPrice[newIndex])
  271.         end
  272.     end
  273. end)
  274.  
  275. shopGui.RightButton.MouseButton1Click:Connect(function()
  276.  
  277.     local currentItem = shopGui.ItemName.Text
  278.  
  279.     if currentShop == "PICKAXE" then
  280.  
  281.         local pickaxesByPrice = {}
  282.         for pickaxe, config in pairs(pickaxesConfig) do
  283.  
  284.             if config.cost > 0 then
  285.                 table.insert(pickaxesByPrice, pickaxe)
  286.             end
  287.         end
  288.  
  289.         table.sort(pickaxesByPrice, function(a, b)
  290.             return pickaxesConfig[a].cost < pickaxesConfig[b].cost
  291.         end)
  292.  
  293.         local currentIndex = table.find(pickaxesByPrice, currentItem)
  294.         if currentIndex and currentIndex < #pickaxesByPrice then
  295.             local newIndex = currentIndex + 1
  296.  
  297.             displayItem(pickaxesByPrice[newIndex])
  298.         end
  299.  
  300.     elseif currentShop == "BACKPACK" then
  301.  
  302.         local backpacksByPrice = {}
  303.         for backpack, config in pairs(backpacksConfig) do
  304.  
  305.             if config.cost > 0 then
  306.                 table.insert(backpacksByPrice, backpack)
  307.             end
  308.         end
  309.  
  310.         table.sort(backpacksByPrice, function(a, b)
  311.             return backpacksConfig[a].cost < backpacksConfig[b].cost
  312.         end)
  313.  
  314.         local currentIndex = table.find(backpacksByPrice, currentItem)
  315.         if currentIndex and currentIndex < #backpacksByPrice then
  316.             local newIndex = currentIndex + 1
  317.  
  318.             displayItem(backpacksByPrice[newIndex])
  319.         end
  320.     end
  321. end)
  322.  
  323.  
  324. --Pickaxe shop
  325. areas.PickaxeShopZone.Touched:Connect(function(hit)
  326.     if hit.Parent == char and shopGui.Enabled == false then
  327.        
  328.         currentShop = "PICKAXE"
  329.        
  330.         if pickaxesConfig[pickaxeValue.Value].cost > 0 then
  331.             displayItem(pickaxeValue.Value)
  332.         else
  333.             local pickaxesByPrice = {}
  334.             for pickaxe, config in pairs(pickaxesConfig) do
  335.  
  336.                 if config.cost > 0 then
  337.                     table.insert(pickaxesByPrice, pickaxe)
  338.                 end
  339.             end
  340.             table.sort(pickaxesByPrice, function(a, b)
  341.                 return pickaxesConfig[a].cost < pickaxesConfig[b].cost
  342.             end)
  343.            
  344.             displayItem(pickaxesByPrice[1])
  345.         end
  346.        
  347.         shopGui.Enabled = true
  348.        
  349.         while (char.HumanoidRootPart.Position - areas.PickaxeShopZone.Position).Magnitude <= areas.PickaxeShopZone.Size.Z/2 do
  350.             task.wait(0.3)
  351.         end
  352.         shopGui.Enabled = false
  353.     end
  354. end)
  355.  
  356. --Backpack shop
  357. areas.BackpackShopZone.Touched:Connect(function(hit)
  358.     if hit.Parent == char and shopGui.Enabled == false then
  359.  
  360.         currentShop = "BACKPACK"
  361.        
  362.         if backpacksConfig[backpackValue.Value].cost > 0 then
  363.             displayItem(backpackValue.Value)
  364.         else
  365.             local backpacksByPrice = {}
  366.             for backpack, config in pairs(backpacksConfig) do
  367.  
  368.                 if config.cost > 0 then
  369.                     table.insert(backpacksByPrice, backpack)
  370.                 end
  371.             end
  372.             table.sort(backpacksByPrice, function(a, b)
  373.                 return backpacksConfig[a].cost < backpacksConfig[b].cost
  374.             end)
  375.  
  376.             displayItem(backpacksByPrice[1])
  377.         end
  378.        
  379.         shopGui.Enabled = true
  380.        
  381.         while (char.HumanoidRootPart.Position - areas.BackpackShopZone.Position).Magnitude <= areas.BackpackShopZone.Size.Z/2 do
  382.             task.wait(0.3)
  383.         end
  384.         shopGui.Enabled = false
  385.     end
  386. end)
  387.  
  388.  
  389. --TP to surface gui
  390. surfaceGui.SurfaceButton.MouseButton1Click:Connect(function()
  391.     char.HumanoidRootPart.CFrame = workspace.SpawnLocation.CFrame + Vector3.new(0, 10, 0)
  392. end)
  393.  
  394.  
  395. --Server requests to this client
  396. re.OnClientEvent:Connect(function(instruction)
  397.    
  398.     if instruction == "FAILED TO LOAD DATA" then
  399.         plrGui.FailedToLoadDataWarning.Enabled = true
  400.     end
  401. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement