2 스크립트에 코드 입력하기

     

    이제 준비가 다 끝났습니다. Teleport 스크립트에 아래의 코드를 입력합니다.

     

    코드 | 파일명: Teleport.lua

    local teleportPart = script.Parent       --Teleport 파트 변수에 담기
    
    --teleport 함수 : 플레이어 캐릭터를 순간이동하는 함수
    local function teleport(otherPart)
        local character = otherPart.Parent   --플레이어 캐릭터 변수에 담기
        --humanoid 변수에 플레이어 케릭터에서 Humanoid 담기
        local humanoid = character:FindFirstChildOfClass("Humanoid")  
        local destination = game.Workspace.Destination   --Destination Part 변수에 담기
        destination.Anchored = true      --Destination 파트 위치 고정
        destination.CanCollide = false   --Destination 파트 CanCollide 기능 끄기
        destination.Transparency = 1     --Destination 파트 안 보이게 투명화하기
    
        if humanoid then   --humanoid 변수에 값이 있으면 아래 코드 실행
            --플에이어 캐릭터의 좌표를 Destination 좌표로 바꾸기
            humanoid.RootPart.CFrame = CFrame.new(destination.Position) 
        end
    end
    
    teleportPart.Touched:Connect(teleport)   --Teleport 파트에 캐릭터가 닿으면 teleport 함수 실
    신간 소식 구독하기
    뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.