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