Im making a the rake game, and im making a script so if the player press Q it changes between classic and lock camera mode
But it isnt changing
Could anyone help me with that?
The Script
local Rep = game:GetService("ReplicatedStorage")
game:GetService("UserInputService").InputBegan:Connect(function(key, processed)
if processed then return end
if key.KeyCode == Enum.KeyCode.Q then
if Rep.FP.Value == true then
game.Players.LocalPlayer.CameraMode = Enum.CameraMode.Classic
Rep.FP.Value = false
end
elseif Rep.FP.Value == false then
game.Players.LocalPlayer.CameraMode = Enum.CameraMode.LockFirstPerson
Rep.FP.Value = true
end
end
Hey @TruckDriv3r!
It seems that you have a syntactical error in some of your if statements, I believe this is likely the cause of it not working. Is it reporting any errors in the output when you press Q?
It should be, I think.
The issue specifically is in this part:
if key.KeyCode == Enum.KeyCode.Q then
if Rep.FP.Value == true then
game.Players.LocalPlayer.CameraMode = Enum.CameraMode.Classic
Rep.FP.Value = false
end
elseif Rep.FP.Value == false then
game.Players.LocalPlayer.CameraMode = Enum.CameraMode.LockFirstPerson
Rep.FP.Value = true
end
Here you’re both missing an end
, and also have one too many just before your elseif
.
After fixing the syntax error it should look like this:
if key.KeyCode == Enum.KeyCode.Q then
if Rep.FP.Value == true then
game.Players.LocalPlayer.CameraMode = Enum.CameraMode.Classic
Rep.FP.Value = false
elseif Rep.FP.Value == false then
game.Players.LocalPlayer.CameraMode = Enum.CameraMode.LockFirstPerson
Rep.FP.Value = true
end
end
Hope this helped!
Oh i didnt see that missing and the wrong end, but it still isnt working, it doesnt changes the camera and it shows no errors at the output
Also, i have this script in ServerScriptService and its a normal script, maybe that is interfering with it? if yes where should i place it and should it also be a local script?
It’s very very strange that you aren’t getting any issues in the console, but your issue seems to be another syntax error that I missed.
Here’s the working code, I tested this myself.
local Rep = game:GetService("ReplicatedStorage")
game:GetService("UserInputService").InputBegan:Connect(function(key, processed)
if processed then return end
if key.KeyCode == Enum.KeyCode.Q then
if Rep.FP.Value then
game.Players.LocalPlayer.CameraMode = Enum.CameraMode.Classic
else
game.Players.LocalPlayer.CameraMode = Enum.CameraMode.LockFirstPerson
end
Rep.FP.Value = not Rep.FP.Value
end
end)
I made some minor changes to include a bit of fancier syntax.
You don’t need to specify == true
in roblox, if it is a boolean value you can just put in the value as the entire expression.
Also you can set the value to the inverse of itself using not
, and not have to repeat the same line twice.
its still not working : /
where did ya put that script?
and is it a local script?
i think that is what is causing the problem
Yes, it is a local script, you can’t get the local player without using a local script. Were you using a server script?
Also, I put it in StarterPlayer > StarterPlayerScripts
yeah i was using a server script lol… ima try it in a local now
oh ima try putting it in starterplayerscripts
It worked after i put at starterPlayer! thx!