This script is supposed to change the Player's CameraType when the Player stops touching a brick.
local Cam = game.Workspace.CurrentCamera script.Parent.TouchedEnded:connect(function(hit) wait(1) if Cam.CameraType == "Scriptable" and game.Players:GetPlayerFromCharacter(hit.Parent) then Cam.CameraType = "Custom" else end end)
Yet, it does not work and doesn't even show an error(yes, this code is in a Local Script).
Errors in your code:
I. You tried to use the Touched
/TouchEnded
events on the client, use a RemoteEvent
and fire the Camera
change to the client, while handling the touch event from the server.
II. You are using deprecated code.RBXScriptSignal:connect()
is deprecated, switch to RBXScriptSignal:Connect()
III. In line 4, CameraType
holds an Enum
value, although technically it’s okay to assign an Enum
value with a string, if you are checking if an Enum
property value equals a specific enum, you must specify the Enum
in conditional statements. These are conditional statements, and if a property holds an Enum
value, the Enum
value must be specified.
Take these for example:
if Character.Humanoid.RigType == Enum.HumanoidRigType.R6 then --code end while PlayerGui.ScreenGui.Frame.Style == Enum.FrameStyle.ChatGreen do -- code end repeat -- code until game.Workspace.Part.Shape == Enum.PartType.Ball
IV. The event is BasePart.TouchEnded
, not TouchedEnded
.
--Server script.Parent.TouchEnded:Connect(function(part) local plr = game:GetService("Players"):GetPlayerFromCharacter(part.Parent) if plr then game.Workspace.ChangeCamType:FireClient(plr) end end)
Code for the remote event.
--Local Script game.Workspace.ChangeCamType.OnClientEvent:Connect(function() local camera = game.Workspace.CurrentCamera if camera.CameraType == Enum.CameraType.Scriptable then -- Here was your error. Must check with an enum in conditional statements. camera.CameraType = Enum.CameraType.Custom --It’s always good to use enums instead of strings to assign enum values, since they are enums. end end)