lua - 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。感谢大家的帮助。我不再需要它
解决方案
问题出在 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等
推荐阅读
- javascript - 如何在函数调用/手动中调用反应路由器 DOM 链接
- javascript - React-slick:在滑动时添加动画
- wpf - WPF Translate 和 Scale 同时,Scale 出现使用原始位置
- python - 根据数据框的名称过滤数据框中的列
- google-bigquery - Big Query 中的 Union Firebase Analytics 数据
- bash - While 循环 ssh 连接
- travis-ci - 使用 Travis CI API 获取存储库的作业日志文件
- azure-logic-apps - 无法查询表存储中的 DateTime 列
- java - 如何仅将 Spring Boot 记录器设置为计划任务?
- wordpress - 如何在产品和自定义帖子类型下拉 CF7 wordpress 插件中设置第一个选项?