Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to update a localscript/part?

Asked by 4 years ago

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

Log in to vote
0
Answered by
karlo_tr10 1233 Moderation Voter
4 years ago

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)
0
Thanks so much! ii_BlueAviation 8 — 4y
0
Can you accept the answer if is that all you need and you don't have questions. karlo_tr10 1233 — 4y
0
I accept the answer? ii_BlueAviation 8 — 4y
0
Um karlo, I think you can't change camera type by using string, you should use Enum values. Block_manvn 395 — 4y
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. karlo_tr10 1233 — 4y
Ad

Answer this question