我如何着手制作更改角色的触摸脚本?

How do I go about making a change character ontouch script?

所以我想制作一个脚本,基本上只要触摸一个方块就调用一个函数,当触摸方块时,只将触摸方块的人的角色更改为另一个角色模型。有人可以帮忙吗?

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)

本地脚本不会 运行 当它们是 child 的一部分时。当有触摸事件时(在这种情况下),他们也不会 运行。使用脚本要容易得多。角色 属性 包含对模型的引用,模型包含人形、body 部分、脚本和其他 objects 模拟玩家头像 in-game 所需的。该模型是工作区的父级,但可以移动。这是一个示例代码:

local PlayersService = game:GetService('Players')

local function Ontouch(part)
    if part.Parent:FindFirstChild("Humanoid") then
       local playerModelName = part.Parent.Name -- gets the name of the player model
       local player = PlayersService:FindFirstChild(playerModelName) 
       player.Character = workspace.Dummy -- write the path to the character you want
   end
end

script.Parent.Touched:Connect(Ontouch)

将其设为脚本(不是本地脚本)并将其设为您想要触摸并获取角色的部分的 child。 为了使相机跟随新分配的角色,您需要编写脚本来执行此操作。