CameraType为什么没有变成Scriptable,但会打印出验证if语句被触发的消息?

huangapple go评论63阅读模式
英文:

Why isn't CameraType changing into Scriptable, but prints the message verifying that the if statement is triggered?

问题

I am trying to make an obby where the camera moves to a specified place with a part when the player steps on the checkpoint.

local cam = game.Workspace.CurrentCamera
local campart = game.Workspace.CameraPart
local checkpoint = script.Parent
local ever = false

checkpoint.Touched:Connect(function(hit)
	local humanoid = hit.Parent:FindFirstChild("Humanoid")
	if humanoid and ever == false then
		cam.CameraType = Enum.CameraType.Scriptable
		cam.CFrame = campart.CFrame
		print("this is supposed to activate the cutscene now")
		ever = true
	end
end)

It doesn't display any errors, and when I step on the checkpoint, it prints the message inside the if statement, but does not change the CFrame of the camera. (The script is inside the checkpoint itself)

I tried to trigger the cutscene without the if statement, but still the camera type will not change to scriptable. I also tried to add a small delay, yet it still doesn't work.

英文:

I am trying to make an obby where the camera moves to a specified place with a part when the player steps on the checkpoint.

local cam = game.Workspace.CurrentCamera
local campart = game.Workspace.CameraPart
local checkpoint = script.Parent
local ever = false

checkpoint.Touched:Connect(function(hit)
	local humanoid = hit.Parent:FindFirstChild("Humanoid")
	if humanoid and ever == false then
		cam.CameraType = Enum.CameraType.Scriptable
		cam.CFrame = campart.CFrame
		print("this is supposed to activate the cutscene now")
		ever = true
	end
end)

It doesn't display any errors, and when I step on the checkpoint, it prints the message inside the if statement, but does not change the CFrame of the camera. (The script is inside the checkpoint itself)

I tried to trigger the cutscene without the if statement, but still the camera type will not change to scriptable. I also tried to add a small delay, yet it still doesn't work.

答案1

得分: 0

`CurrentCamera`在普通脚本中无法使用,但在本地脚本中可以。

以下代码应该可行:
local campart = game.Workspace.CameraPart
local checkpoint = script.Parent
local ever = false

checkpoint.Touched:Connect(function(hit)
if not hit.Parent:FindFirstChild("Humanoid") or ever == true then return end
    local humanoid = hit.Parent.Humanoid
    local cam = hit.Parent.Head.Camera
    cam.CameraType = Enum.CameraType.Scriptable
    cam.CFrame = campart.CFrame
    print("现在应该激活过场动画")
    ever = true
    end
end)

<details>
<summary>英文:</summary>

`CurrentCamera` doesn&#39;t work in normal scripts but does in local scripts.

This should work:
local campart = game.Workspace.CameraPart
local checkpoint = script.Parent
local ever = false

checkpoint.Touched:Connect(function(hit)
if not hit.Parent:FindFirstChild(&quot;Humanoid&quot;) or ever = true then return end
    local humanoid = hit.Parent.Humanoid
    local cam = hit.Parent.Head.Camera
    cam.CameraType = Enum.CameraType.Scriptable
    cam.CFrame = campart.CFrame
    print(&quot;this is supposed to activate the cutscene now&quot;)
    ever = true
    end
end)

</details>



huangapple
  • 本文由 发表于 2023年6月30日 00:42:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76583037.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定