Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Servers don't free the Camera more than once each life?

I am making a cryo-freeze chamber which you can view in action here.

When you are frozen, CamFreeze is parented to your Character and run:

local cam = workspace.CurrentCamera
cam.CameraType = Enum.CameraType.Scriptable

local val = script:WaitForChild("Value")

cam.CoordinateFrame = CFrame.new(
	val.Value,
	script.Parent.Head.Position
)

repeat wait() until script.Parent.Head.Anchored

cam.CoordinateFrame = CFrame.new(
	val.Value,
	script.Parent.Head.Position
)

script:Destroy()

And, when thawed, CamThaw:

local cam = workspace.CurrentCamera
cam.CameraType = Enum.CameraType.Custom
cam.CameraSubject = script.Parent.Humanoid

script:Destroy()

My problem is that CamThaw isn't fixing the Player's camera more than once each life. CamFreeze appears to work every time, but CamThaw only works the first time in online and Test Servers. (Test Server players are also unable to actually click the SurfaceGui button, but that's probably a ROBLOX bug as it works in Online Servers.)

What can I do to get this to work? I'm much prefer to have the camera manipulation, because otherwise the only way out of the chamber is to have someone else release you or to reset your character.

5 comments

0

Is the CameraSubject changing? Like, if you do print(cam.CameraSubject) will it print Humanoid?

0

I dunno this code looks good.

0

It prints "Humanoid" before and after. I changed the code in CamFreeze to set it to nil, and it will print nil before and Humanoid after, but it still doesn't work more than once.

0

If it actually IS changing the camera subject, then I don't know. I've run into errors like this before, where you change something but it doesn't behave as if changed. Probably a Roblox error.

0

Well that's annoying. I may have to resort to calling LoadCharacter on it, which requires a dozen more lines of sanity checking. :/

1 answer

✓ Accepted answer

I reduced the two scripts to this:

-- Freeze
local cam = workspace.CurrentCamera
cam.CameraType = Enum.CameraType.Scriptable
wait();
cam.CoordinateFrame = CFrame.new(10, 10, 10);
script:Destroy()
-- Thaw
local cam = workspace.CurrentCamera
cam.CameraType = Enum.CameraType.Custom
cam.CameraSubject = script.Parent.Humanoid
wait();
script:Destroy()

and it seemed to work as expected.

Perhaps the problem is the thing that is adding the localscripts, rather than the localscripts themselves?

3 comments

1

The script adding the LocalScripts is working perfectly. The LocalScripts load and they will run print() statements, but it just wasn't working. I don't know why, but adding the wait() to the thaw LocalScript fixed the issue. Why would that matter?

0

When a script tries to delete itself as soon as it is parented, an exception is thrown. I'm not exactly sure why that would cause a problem in this case, though.

0

I've seen the error before, and I wasn't even getting it here, the camera simply wasn't working. It works now, though, with the wait(). Very strange.

This discussion is preserved as it was. New answers, comments, and votes are closed.