Local Script won't run

I have developed a camera-changing system with 3 parts. A green part once hit will update all player’s cameras to the CFrame of the blue part. The red part once hit will revert their cameras back to their respective players.

The green and red parts are in this model
The value is the objectvalue to the blue part for the camera variable
The localscript contains functions that will be triggered by remote-events
image
The problem is in the local script, where the green/red parts will be touched, but it won’t fire the remote events and no errors show up.

wait(0.2)
local cam=workspace.CurrentCamera
local player=game.Players.LocalPlayer
local Cam = script.Parent.CameraPart

game.ReplicatedStorage.WatchTrainGoUpCutscene.OnClientEvent:Connect(function(start)
game:GetService(“RunService”).RenderStepped:connect(function(start)
cam.CameraSubject=Cam.Value
cam.CameraType=(“Scriptable”)
cam.CoordinateFrame = Cam.Value:GetRenderCFrame()
player.CameraMaxZoomDistance=.6
cam.FieldOfView = 50
print(“it works”)
end)

end)

game.ReplicatedStorage.TrainWatchStop.OnClientEvent:Connect(function(complete)

cam.CameraType = (“Custom”)
cam.CameraSubject=player.Character.Humanoid
player.CameraMaxZoomDistance=128
cam.FieldOfView = 70

end)

Can anyone figure out why? I put in a print statement to test it and it wouldn’t print either.

If anyone finds it useful, here is the script that detects a touched event for the green/red parts.
image

game.Workspace.FlatTop1.Start.Touched:Connect(function()

game.ReplicatedStorage.WatchTrainGoUpCutscene:FireAllClients()
script.Disabled=true

wait(2000)
script.Disabled=false

end)

(Similar to my last post, I’ve rethought the process for my idea and I’ve gotten a little closer)

1 Like

Is the local script is within the model in workspace? If so then it will not run at all, so move it to where it will run in these players:

A LocalScript will only run Lua code if it is a descendant of one of the following objects:
A Player’s Backpack, such as a child of a Tool
A Player’s character model
A Player’s PlayerGui
A Player’s PlayerScripts.
The ReplicatedFirst service

In my perspective the model with the local script inside is probably inside of Workspace. The local script doesn’t run in Workspace. You can try moving the local script as the post above, says on where local scripts run at.

There’s an exclusion to this, for player characters.

Ive moved it into StarterGui, and it appears to be trying to work now. Although I get this error:

I don’t understand this? Nil? I referenced the camera’s variable though…
image

You should be using the local script that changes the camera in StarterGui, and not inside of the model. Use RemoteEvents to fire it between the server and client.

So I got the first part working, where something hits the green part and your camera changes.
I’ve also edited the bottom half.
image
The remote event fires, and it successfully prints what I want it to. But the camera doesn’t change? I am suspecting it is because of this line V
image
But I need this line so that the camera moves with the part that it locks onto.

On my recent post on this thread, could you help? It prints the statement like it should, but it appears to skip every other line before it.

just spawn script inside the part and put runcontext to local

Why did you decide to reply 3 years later

1 Like

i dont know, i was just searching the devforum :stuck_out_tongue: