如何制作一个基于触摸脚本的角色改变脚本?

我想制作一个脚本,在块被触摸时调用一个函数,并且在块被触摸时,仅更改触摸块的角色模型。有谁能帮忙吗?

local circle = script.Parent
local plr = game.Players.LocalPlayer
circle.Touched:Connect(function(part)
if part.Parent:FindFirstChild("Humanoid") then
    plr.Character = "O"
end
end)
点赞
用户15107943
用户15107943

本地脚本在它们是 part 的子对象时不会运行。在此情况下,也不会运行触摸事件。使用脚本会更容易些。Character 属性包含引用一个模型,其中包含 Humanoid、身体部位、脚本和其他在游戏中模拟玩家角色所需的对象。模型被设置为 Workspace 的父对象,但可以被移动。这是一个示例代码:

local PlayersService = game:GetService('Players')

local function Ontouch(part)
    if part.Parent:FindFirstChild("Humanoid") then
       local playerModelName = part.Parent.Name -- 获取玩家模型的名称
       local player = PlayersService:FindFirstChild(playerModelName)
       player.Character = workspace.Dummy -- 编写想要的角色路径
   end
end

script.Parent.Touched:Connect(Ontouch)

将此脚本设置为 part 的子对象而不是本地内容,并获取角色。为了使相机跟随新分配的角色,您需要编写一个脚本来实现。

2021-01-30 22:57:02