Advertisement
Anukun_Lucifer

OpenDoorScript

Aug 6th, 2024
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.80 KB | Gaming | 0 0
  1. -- เรียกใช้บริการ Players เพื่อเข้าถึงข้อมูลผู้เล่นในเกม
  2. local Players = game:GetService("Players")
  3.  
  4. -- เก็บ Object opendoor ซึ่งเป็น Parent ของสคริปต์นี้ไว้ในตัวแปร
  5. local opendoor = script.Parent
  6.  
  7. -- รอจนกว่าจะพบวัตถุที่ชื่อ OutDoor ใน Workspace แล้วเก็บไว้ในตัวแปร
  8. local OutDoor = workspace:WaitForChild("OutDoor")
  9.  
  10. -- รอจนกว่าจะพบ Sound ที่ชื่อ Open5 ภายใน opendoor แล้วเก็บไว้ในตัวแปร
  11. local Sound = opendoor:WaitForChild("Open5")
  12.  
  13. -- ตัวแปรเพื่อป้องกันการทำงานซ้ำซ้อน
  14. local debounce = false
  15.  
  16. -- เมื่อมีส่วนใดของตัวละครมาแตะ opendoor
  17. opendoor.Touched:Connect(function(touchPart)
  18.     -- หาตัวละครจาก Parent ของ part ที่มาแตะ
  19.     local character = touchPart.Parent
  20.     if not character then return end
  21.  
  22.     -- หาผู้เล่นจากตัวละครที่ได้มา
  23.     local player = Players:GetPlayerFromCharacter(character)
  24.     if not player then return end
  25.  
  26.     -- หาวัตถุ HumanoidRootPart ภายในตัวละคร
  27.     local hrp = character:FindFirstChild("HumanoidRootPart")
  28.     if not hrp then return end
  29.  
  30.     -- ถ้า debounce เป็น false (เพื่อป้องกันการทำงานซ้ำซ้อน)
  31.     if debounce == false then
  32.         -- ตั้งค่า debounce เป็น true เพื่อป้องกันการทำงานซ้ำซ้อน
  33.         local debounce = true
  34.         print("Door Open")
  35.  
  36.         -- เล่นเสียงเปิดประตู
  37.         Sound:Play()
  38.  
  39.         -- ตั้งค่าตำแหน่งการ Teleport
  40.         local Teleportlocation = CFrame.new(OutDoor.CFrame.X-1, OutDoor.CFrame.Y, OutDoor.CFrame.Z+8)
  41.         -- ย้าย HumanoidRootPart ไปยังตำแหน่งใหม่
  42.         hrp.CFrame = Teleportlocation
  43.  
  44.         -- ตั้งค่า CameraMaxZoomDistance และ CameraMinZoomDistance ของผู้เล่น
  45.         player.CameraMaxZoomDistance = 3
  46.         player.CameraMinZoomDistance = 3
  47.  
  48.         -- ตั้งค่า JumpHeight ของ Humanoid ในตัวละคร
  49.         character.Humanoid.JumpHeight = 2.5
  50.  
  51.         -- รอเวลา 1 หน่วย (1/30 วินาที)
  52.         task.wait()
  53.  
  54.         -- ตั้งค่า debounce กลับเป็น false เพื่อให้สามารถทำงานได้อีกครั้ง
  55.         debounce = false
  56.     end
  57. end)
  58.  
Tags: Roblox
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement