ShorelineLsuiza

Construir ponte - atual

Jul 25th, 2024
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.31 KB | Gaming | 0 0
  1. 1° ESTÁVEL -----
  2.  
  3. local ProximityPrompt = script.Parent
  4. local player = game.Players.LocalPlayer
  5. local Ponte = workspace.Fase1_Ponte.Secao1 -- Suponho que 'Pontee' seja um objeto no 'workspace'
  6. local Gui = nil  -- Vamos armazenar a GUI como variável global
  7.  
  8. ProximityPrompt.Triggered:Connect(function(player)
  9.     if player then
  10.         local inHand = player.Character and player.Character:FindFirstChild('Placa de madeira')
  11.         local inBackpack = player.Backpack and player.Backpack:FindFirstChild('Placa de madeira')
  12.         local inHand = player.Character and player.Character:FindFirstChild('Nó 1')
  13.         local inBackpack = player.Backpack and player.Backpack:FindFirstChild('Nó')
  14.  
  15.         if inHand or inBackpack then
  16.             Ponte.Material = Enum.Material.Wood
  17.             Ponte.BrickColor = BrickColor.new("Rust")
  18.             Ponte.CanCollide = true
  19.  
  20.             -- Oculta a GUI se ela existir
  21.             if Gui then
  22.                 Gui:Destroy()
  23.                 Gui = nil
  24.             end
  25.         else
  26.             -- Cria a GUI se ela não existir
  27.             if not Gui then
  28.                 Gui = Instance.new("ScreenGui")
  29.                 Gui.Parent = player.PlayerGui
  30.  
  31.                 local ImageLabel = Instance.new("ImageLabel")
  32.                 ImageLabel.Parent = Gui
  33.                 ImageLabel.Size = UDim2.new(0.2, 0, 0.2, 0)
  34.                 ImageLabel.Position = UDim2.new(0.417, 0,-0.01, 0)
  35.                 ImageLabel.BackgroundTransparency = 1
  36.                 ImageLabel.ScaleType = Enum.ScaleType.Crop
  37.                 ImageLabel.Image = "rbxassetid://18644825733"
  38.                 ImageLabel.Visible = true
  39.  
  40.                 -- Define um timer para ocultar a GUI após 2 segundos
  41.                 spawn(function()
  42.                     wait(2)
  43.                     if Gui and Gui.Parent then
  44.                         Gui:Destroy()
  45.                         Gui = nil
  46.                     end
  47.                 end)
  48.             end
  49.         end
  50.     end
  51. end)
  52.  
  53.  
  54.  
  55. --------------------
  56.  
  57. 2° ESTÁVEL
  58.  
  59. local Players = game:GetService("Players")
  60. local ProximityPrompt = script.Parent
  61. local Ponte = workspace.Fase1_Ponte.Secao1 -- Suponho que 'Ponte' seja um objeto no 'workspace'
  62. local Gui = nil  -- Vamos armazenar a GUI como variável global
  63.  
  64. local player = Players.LocalPlayer
  65.  
  66. -- Função para verificar os itens na mochila
  67. local function checkBackpackItems()
  68.     -- Verifica se o jogador está presente e se ele tem um personagem
  69.     if player and player.Character and player.Character:IsDescendantOf(game.Workspace) then
  70.         -- Verifica se ambos os itens estão na mochila do jogador
  71.         local hasWoodPlankInBackpack = player.Backpack and player.Backpack:FindFirstChild('Placa de madeira')
  72.         local hasKnotInBackpack = player.Backpack and player.Backpack:FindFirstChild('Nó 1')
  73.  
  74.         print("Placa de madeira na mochila:", hasWoodPlankInBackpack)
  75.         print("Nó 1 na mochila:", hasKnotInBackpack)
  76.  
  77.         if hasWoodPlankInBackpack and hasKnotInBackpack then
  78.             print("Ambos os itens encontrados na mochila. Alterando a Ponte...")
  79.  
  80.             -- Ambos os itens estão na mochila, então altera o material da Ponte
  81.             Ponte.Material = Enum.Material.Wood
  82.             Ponte.BrickColor = BrickColor.new("Rust")
  83.             Ponte.CanCollide = true
  84.  
  85.             -- Oculta a GUI se ela existir
  86.             if Gui then
  87.                 Gui:Destroy()
  88.                 Gui = nil
  89.             end
  90.         else
  91.             print("Um ou ambos os itens não estão na mochila. Mostrando GUI...")
  92.  
  93.             -- Cria a GUI se ela não existir
  94.             if not Gui then
  95.                 Gui = Instance.new("ScreenGui")
  96.                 Gui.Parent = player.PlayerGui
  97.  
  98.                 local ImageLabel = Instance.new("ImageLabel")
  99.                 ImageLabel.Parent = Gui
  100.                 ImageLabel.Size = UDim2.new(0.2, 0, 0.2, 0)
  101.                 ImageLabel.Position = UDim2.new(0.417, 0, -0.01, 0)
  102.                 ImageLabel.BackgroundTransparency = 1
  103.                 ImageLabel.ScaleType = Enum.ScaleType.Crop
  104.                 ImageLabel.Image = "rbxassetid://18644825733"
  105.                 ImageLabel.Visible = true
  106.  
  107.                 -- Define um timer para ocultar a GUI após 2 segundos
  108.                 spawn(function()
  109.                     wait(2)
  110.                     if Gui and Gui.Parent then
  111.                         Gui:Destroy()
  112.                         Gui = nil
  113.                     end
  114.                 end)
  115.             end
  116.         end
  117.     else
  118.         print("Jogador ou personagem não encontrados. Aguardando...")
  119.         -- Conecta o evento PlayerAdded para garantir que obtemos o jogador corretamente
  120.         local function onPlayerAdded(newPlayer)
  121.             player = newPlayer
  122.             checkBackpackItems()
  123.         end
  124.         Players.PlayerAdded:Connect(onPlayerAdded)
  125.     end
  126. end
  127.  
  128. -- Conectar a função ao evento Triggered do ProximityPrompt
  129. ProximityPrompt.Triggered:Connect(function()
  130.     print("Triggered! Verificando itens na mochila...")
  131.     checkBackpackItems()
  132. end)
  133.  
  134. -- Verificar os itens na mochila quando o script é iniciado
  135. checkBackpackItems()
  136.  
  137.  
  138. ------------------
  139. 3º ESTÁVEL
Advertisement
Add Comment
Please, Sign In to add comment