英文:
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'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("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("this is supposed to activate the cutscene now")
ever = true
end
end)
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论