I’ve been trying to freeze the camera on an npc’s head and I am using a remoteevent to do so. When I try to run it, I get this error:
Unable to assign property CFrame. CoordinateFrame expected, got nil - Client - LocalScript:6
These are the two scripts I am using to fire the event.
LocalScript:
local Jumpscare = game.ReplicatedStorage:WaitForChild("Jumpscare")
local Camera = workspace.CurrentCamera
Jumpscare.OnClientEvent:Connect(function(player,cframe)
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = cframe
end)
Server Script (Inside a hitbox part inside of a HumanoidRootPart):
local Jumpscare = game.ReplicatedStorage:WaitForChild("Jumpscare")
local RS = game:GetService("RunService")
local Camera = workspace.CurrentCamera
local Character = script.Parent.Parent.Parent
script.Parent.Touched:Connect(function(t)
print("touched")
if t.Parent:FindFirstChild("Humanoid") and t.Parent ~= Character and game.Players:GetPlayerFromCharacter(t.Parent) then
Jumpscare:FireClient(game.Players:GetPlayerFromCharacter(t.Parent), Character.Head.CFrame * CFrame.new(0,2,0))
Character.HumanoidRootPart.Anchored = true
Character.Slap.Enabled = false
end
end)
2 Likes
If it’s the client receiving the RemoteEvent, the player will always be the LocalPlayer so the first parameter isn’t used.
Jumpscare.OnClientEvent:Connect(function(cframe)
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = cframe
end)
(and the server side)
script.Parent.Touched:Connect(function(t)
print("touched")
if t.Parent:FindFirstChild("Humanoid") and t.Parent ~= Character and game.Players:GetPlayerFromCharacter(t.Parent) then
Jumpscare:FireClient(Character.Head.CFrame * CFrame.new(0,2,0))
Character.HumanoidRootPart.Anchored = true
Character.Slap.Enabled = false
end
end)
2 Likes
It didn’t let me use only the CFrame variable. It had to have a player in the parameters.
1 Like
I mean if you don’t believe me I hope you believe the official documentation at least. Just look at the parameters and you’ll see
1 Like
I tried it and ended up with this error:
Unable to cast value to Object
on the line where the event is fired. I tried removing the multiplication and switching it over to the localscript and it did nothing.
1 Like
forgot to mention it’s in the server script.
1 Like
bumping this, no one seems to be responding.
1 Like
I need more people to reply to this. Its still not solved and I don’t know where to continue.
Oops my mistake on the event line, corrected:
Jumpscare:FireClient(game.Players:GetPlayerFromCharacter(t.Parent), Character.Head.CFrame * CFrame.new(0,2,0))
The client doesn’t need the player since it’s always the localplayer but the server has to know which player to fire the remote to
1 Like
Unlike OnServerEvent
, OnClientEvent
does not have the Player as the first parameter. The reason why FireClient
needs a Player as the first argument is because FireClient can only be used on the server-side, and the server doesn’t know which player you’d like to send data to, so you’ll need to tell the server by providing the player as the first argument (Unlike FireAllClients
, which does not need to know which player to send data to, since it sends data to all players currently present in your game)
If you were to replace your code with this:
local Jumpscare = game.ReplicatedStorage:WaitForChild("Jumpscare")
local Camera = workspace.CurrentCamera
Jumpscare.OnClientEvent:Connect(function(player,cframe)
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = player
end)
It will work without a problem, which is because as I previously mentioned, OnClientEvent
does not have the Player as the first parameter, so what’s happening is that the parameter named player
is actually the CFrame value you’re sending, and the parameter named cframe
is nil, which is the reason why you’re experiencing this error