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

How to update a localscript/part?

So I currently have this local script:

local Camera = game.Workspace.CurrentCamera
local Player = game.Players.LocalPlayer

script.Parent.MouseButton1Down:Connect(function()
	repeat wait() until Player.Character
	Camera.CameraType = "Scriptable"
	Camera.CFrame = game.Workspace.A320.PlaneKit.Plane.Plane.OtherParts.Body.CameraParts.Tail.CFrame

script.Parent.Enabled = true

end)

So, when you click the button, it goes to a part inside the A320 model. It works and you can see it.

However, when the A320 model moves, it just stays in the same place (the part moves but the playercamera won't.)

I have tried doing loops etc but it does not seem to be working. I'm a bit new to scripting at the moment.

1 answer

✓ Accepted answer

Here is my solution:

local Camera = game.Workspace.CurrentCamera
local Player = game.Players.LocalPlayer

script.Parent.MouseButton1Down:Connect(function()
    repeat wait() until Player.Character
    Camera.CameraType = "Scriptable"
	spawn(function() -- So the rest of the script doesn't yeld.
		while wait() do -- Could use RenderStepped:Wait() but this will be fine for now.
			if not Player.Character then break end -- Breaks the loop if character is removed
			Camera.CFrame = game.Workspace.A320.PlaneKit.Plane.Plane.OtherParts.Body.CameraParts.Tail.CFrame
		end
	end)  
	script.Parent.Enabled = true
end)

5 comments

0

Thanks so much!

0

Can you accept the answer if is that all you need and you don't have questions.

0

I accept the answer?

0

Um karlo, I think you can't change camera type by using string, you should use Enum values.

0

You are correct to be honest I didn't even focus on that assuming it worked as he stated that it did with original script, but yes enums should be used.

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