首页 > 解决方案 > Roblox ClickDetector 有问题

问题描述

我在 Roblox 上的脚本无论是在编辑器中还是在本地服务器中运行都不起作用。我不知道我哪里出错了,所以我只发布整个脚本

player = game.Players.Player --you might want to change this...
target = Vector3.new(20, 10, 20) --...and this

local ClickDetector = Instance.new("ClickDetector")
ClickDetector.Parent = workspace["Decal and teleporter"]
ClickDetector.MaxActivationDistance = 1000



function fadeTo(a, b, c)
    for transparency = a, b, c do
    --go from a to b, counting by c

        for _, part in pairs(player.Character:GetChildren()) do
        --for each of the objects in the character,

            if part:IsA("BasePart") then
            --check if it's a part, and if so

                part.Transparency = transparency
                --set its transparency
            end
        end
        wait(0.1)
    end
end

ClickDetector.MouseClick:Connect(function()
    fadeTo(0, 1, 0.1) --fade out
    player.Character.HumanoidRootPart.CFrame = target --teleport the player
    fadeTo(1, 0, -0.1) --fade back in
end)

我应该尝试发布它然后在那里测试吗?

编辑:我犯了一个大错误。我将零件尺寸设置为 1000,但忘记更改 MaxActivationDistance。感谢大家的帮助。我不再需要它

标签: luaroblox

解决方案


问题出在 ClickDetector 的功能上,看

target = Vector3.new(20, 10, 20) --...and this
player.Character.HumanoidRootPart.CFrame = target

将其更改为

target = CFrame.new(Vector3.new(20, 10, 20)) --...and this
player.Character.HumanoidRootPart.CFrame = target

说明:不能将CFrame值设置为Vector3值,其中CFrame为Vector3、Orientation等


推荐阅读