Im trying to make an attack on titan game and I want to make the titan shifter power first, I scripted it so when they press F they change into a titan, I already scripted it so the camera would stick to the titan but the body wont move so i made it so the character changes into the titan but i am getting an error that im trying to index nil with Character which i said like 'local char = plr.Character' I dont know why im getting an error, I clearly described plr as game.Players.LocalPlayer so why am i getting this error! am i not suppose to do this script in a server script and a local script? I tried that already in a local script i cant use OnServerEvent. BTW This is both the scripts right here :
Server Script :
--Variables
local event = game.ReplicatedStorage.Remotes.BeginTitanShift
local plr = game.Players.LocalPlayer
local char = plr.Character
local rig = game.Workspace.PlayerShifterTitan
--Code
event.OnServerEvent:Connect(function(shift)
local camera = workspace.CurrentCamera
camera.CameraType = "Follow"
camera.CameraSubject = rig.HumanoidRootPart
script.Parent.RemoteEvent:FireServer()
char = rig
end)
Local Script(In StarterCharacterScripts) :
--Variables
local key = Enum.KeyCode.F
local uis = game:GetService("UserInputService")
local event = game.ReplicatedStorage.Remotes.BeginTitanShift
local player = game.Players.LocalPlayer
--Code
uis.InputBegan:Connect(function(input, g)
if g then return end
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == key or Enum.KeyCode.F then
event:FireServer()
end
end
end)
If you know the error tell me plzzzzz

1 comment
Attempt to index nil with something means; that the instance/thing you're trying to reference, does not exist! Also, localplayer does not work with the server. And when using remoteevents the first parameter MUST always be a player.