I am trying to create a chat command (one you can type in-game and activate the function) to either lock someone in first person or allow them to zoom out once again. My problem is getting the command to send it to the players. So far I have this in the localscript:
function game.Workspace.OnClientInvoke(FirstPerson) game:GetService('Players').LocalPlayer.CameraMode = Enum.CameraMode.LockFirstPerson end function game.Workspace.OnClientInvoke(ThirdPerson) game:GetService('Players').LocalPlayer.CameraMode = Enum.CameraMode.LockFirstPerson end
And this in the Server Script:
function onCommand(message, player) if message:sub(1, 12) == ":firstperson" and TrueAdmin[player.Name] then local CameraMode = Instance.new("Camera Mode") CameraMode.Parent = game.Workspace CameraMode.Name = "First Person" function CameraMode(player) local success, result = pcall(function() return CameraMode:InvokeClient(player) end) if success then print(result) else print("Not able to change Camera Mode") end end end if message:sub(1, 12) == ":thirdperson" and TrueAdmin[player.Name] then local CameraMode = Instance.new("Camera Mode") CameraMode.Parent = game.Workspace CameraMode.Name = "First Person" function CameraMode(player) local success, result = pcall(function() return CameraMode:InvokeClient(player) end) if success then print(result) else print("Not able to change Camera Mode") end end end end -- Chat commands are working. I have already got that and these are in a function.
EDIT: Edited on mobile. So pardon the missed tabs.
Thanks a lot for helping me out. I realize that I may have been asking quite a few questions, but thank you so much.
Your problem is that you're using ServerScriptStorage
for storing something that you want to use to manipulate the client.
Look closer: ServerScriptService
See why it's not working now?
Store your RemoteFunction
in ReplicatedStorage
and then you should be set(: