Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- เรียกใช้บริการ Players เพื่อเข้าถึงข้อมูลผู้เล่นในเกม
- local Players = game:GetService("Players")
- -- เก็บ Object opendoor ซึ่งเป็น Parent ของสคริปต์นี้ไว้ในตัวแปร
- local opendoor = script.Parent
- -- รอจนกว่าจะพบวัตถุที่ชื่อ OutDoor ใน Workspace แล้วเก็บไว้ในตัวแปร
- local OutDoor = workspace:WaitForChild("OutDoor")
- -- รอจนกว่าจะพบ Sound ที่ชื่อ Open5 ภายใน opendoor แล้วเก็บไว้ในตัวแปร
- local Sound = opendoor:WaitForChild("Open5")
- -- ตัวแปรเพื่อป้องกันการทำงานซ้ำซ้อน
- local debounce = false
- -- เมื่อมีส่วนใดของตัวละครมาแตะ opendoor
- opendoor.Touched:Connect(function(touchPart)
- -- หาตัวละครจาก Parent ของ part ที่มาแตะ
- local character = touchPart.Parent
- if not character then return end
- -- หาผู้เล่นจากตัวละครที่ได้มา
- local player = Players:GetPlayerFromCharacter(character)
- if not player then return end
- -- หาวัตถุ HumanoidRootPart ภายในตัวละคร
- local hrp = character:FindFirstChild("HumanoidRootPart")
- if not hrp then return end
- -- ถ้า debounce เป็น false (เพื่อป้องกันการทำงานซ้ำซ้อน)
- if debounce == false then
- -- ตั้งค่า debounce เป็น true เพื่อป้องกันการทำงานซ้ำซ้อน
- local debounce = true
- print("Door Open")
- -- เล่นเสียงเปิดประตู
- Sound:Play()
- -- ตั้งค่าตำแหน่งการ Teleport
- local Teleportlocation = CFrame.new(OutDoor.CFrame.X-1, OutDoor.CFrame.Y, OutDoor.CFrame.Z+8)
- -- ย้าย HumanoidRootPart ไปยังตำแหน่งใหม่
- hrp.CFrame = Teleportlocation
- -- ตั้งค่า CameraMaxZoomDistance และ CameraMinZoomDistance ของผู้เล่น
- player.CameraMaxZoomDistance = 3
- player.CameraMinZoomDistance = 3
- -- ตั้งค่า JumpHeight ของ Humanoid ในตัวละคร
- character.Humanoid.JumpHeight = 2.5
- -- รอเวลา 1 หน่วย (1/30 วินาที)
- task.wait()
- -- ตั้งค่า debounce กลับเป็น false เพื่อให้สามารถทำงานได้อีกครั้ง
- debounce = false
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement