📌  相关文章
📜  如何将玩家传送到 roblox studio 中的对象 - 无论代码示例

📅  最后修改于: 2022-03-11 15:00:33.104000             🧑  作者: Mango

代码示例1
local ReplicatedStorage = game:GetService("ReplicatedStorage")local Players = game:GetService("Players") local TeleportWithinPlace = {} -- Create remote event instancelocal teleportEvent = Instance.new("RemoteEvent")teleportEvent.Name = "TeleportEvent"teleportEvent.Parent = ReplicatedStorage function TeleportWithinPlace.Teleport(humanoid, params)    local character = humanoid.Parent     -- Freeze character during teleport if requested    if params.freeze then        humanoid:SetAttribute("DefaultWalkSpeed", humanoid.WalkSpeed)        humanoid:SetAttribute("DefaultJumpPower", humanoid.JumpPower)        humanoid.WalkSpeed = 0        humanoid.JumpPower = 0    end     -- Calculate height of root part from character base    local rootPartY    if humanoid.RigType == Enum.HumanoidRigType.R15 then        rootPartY = (humanoid.RootPart.Size.Y * 0.5) + humanoid.HipHeight    else        rootPartY = (humanoid.RootPart.Size.Y * 0.5) + humanoid.Parent.LeftLeg.Size.Y + humanoid.HipHeight    end     -- Teleport player and request content around location if applicable    local position = CFrame.new(params.destination + Vector3.new(0, rootPartY, 0))    local orientation = CFrame.Angles(0, math.rad(params.faceAngle), 0)    if workspace.StreamingEnabled then        local player = Players:GetPlayerFromCharacter(character)        player:RequestStreamAroundAsync(params.destination)    end    character:SetPrimaryPartCFrame(position * orientation)     -- Unfreeze character    if params.freeze then        humanoid.WalkSpeed = humanoid:GetAttribute("DefaultWalkSpeed")        humanoid.JumpPower = humanoid:GetAttribute("DefaultJumpPower")    endend return TeleportWithinPlace