Unable to cast value to object

What is the issue? Issue is the error that comes up no matter what I can’t figure out how to fix it, the camera position won’t change because the error stops the event

The goal is a jumpscare

Client side

local TweenService = game:GetService("TweenService")
local player = game.Players.LocalPlayer
local CameraIn = game.ReplicatedStorage.Remotes.CameraIn
local PlayerCamera = game.ReplicatedStorage.Remotes.PlayerCamera

function shake() local camera = game.Workspace.Camera for i = 1,10 do wait() 
		camera.CoordinateFrame = camera.CoordinateFrame * CFrame.new(0,2,0) wait() 
		camera.CoordinateFrame = camera.CoordinateFrame * CFrame.new(0,-2,0) end end

CameraIn.OnClientEvent:Connect(function(Position,Focus,Time)
	print(1)
			local cam = game.Workspace.Camera
	        cam.CameraType = Enum.CameraType.Scriptable
	cam:Interpolate(Position,Focus,Time)
	print(4)
            shake()
	        script.Sound:Play()
			
end)


PlayerCamera.OnClientEvent:Connect(function()
	local camera = game.Workspace.Camera
	script.Sound:Stop()
	camera.CameraType = Enum.CameraType.Custom

end)

Server side

local played = false
local CameraIn = game.ReplicatedStorage.CameraIn

script.Parent.T.Touched:Connect(function(v)
	if v.Parent:FindFirstChild("Humanoid") then
		if played == false then
			played = true
			print(3)
			CameraIn:FireClient(workspace.CameraPosition.CFrame, workspace.CameraAim.CFrame, 5)
			print(1)
			wait(1)
			played = false
			v.Parent.Humanoid.Health = 0
		end
	end
end)

Just to make sure you understand it’s an interpolation I’m trying to make with TweenService
CameraAim and CameraPosition are parts pointed to the scene I want to make

try game.Workspace.CurrentCamera instead of .Camera and maybe a miracle will happen or maybe not

also what is CoordinateFrame? if it’s a value stored in an instance and not an actualy property, perhaps you forgot to add .Value

Haha, same issue as it doesn’t matter what’s on the client side because the event doesn’t even fire when the error comes up

FireClient() requires a player object as first parameter but you are instead sending a CFrame. The player object must be the player who the server must fire the event to

Also Camera:Interpolate() is deprecated and you should use TweenService instead

FireAllClients will be different right? #30cjsflsggsag

FireAllClients() and FireClient() both fire an event but the difference is that, FireAllClients() will fire the event for all the player and therefore does not require a player object while FireClient() fires the event for a player only and so to identify the player it needs a player object

Ok, then I can use FireAllClients for tests and then figure out how to define player when I change it to fireclient instead of tweening and remaking it?

Using the interploate^^

Since you are connecting the callback that fires the event to a .Touched event you can obtain the player object from the character using GetPlayerFromCharacter()

local played = false
local CameraIn = game.ReplicatedStorage.CameraIn

script.Parent.T.Touched:Connect(function(v)
	if v.Parent:FindFirstChild("Humanoid") then
		local plr = game.Players:GetPlayerFromCharacter(v)
		if played == false then
			played = true
			print(3)
			CameraIn:FireClient(plr["PlayerName"], workspace.CameraPosition.CFrame, workspace.CameraAim.CFrame, 5)
			print(1)
			wait(1)
			played = false
			v.Parent.Humanoid.Health = 0
		end
	end
end)

image

just plr gets sent into function, not its name

Tried but I have to or else this error will come up " FireClient: player argument must be a player object."

because you need to pass v.Parent, not v into getplayerfromchar

Did I? #30SDIKGJSGsgsgsasgfasfagsfsa

1 Like

Nevermind same error comes up

CameraIn:FireClient(v.Parent, workspace.CameraPosition.CFrame, workspace.CameraAim.CFrame, 5)

image

because I said use v.Parent in GetPlayerFromCharacter()

v is the part touching and not the character model. Get the character using v.Parent

Mb & thanks, but the issue has moved to the client now as the camera won’t change its position to the requested parameters and not even fires as if I’d seen the print(1) at the beginning of the .OnClientEvent function

local player = game.Players.LocalPlayer
local CameraIn = game.ReplicatedStorage.Remotes.CameraIn
local PlayerCamera = game.ReplicatedStorage.Remotes.PlayerCamera

function shake() local camera = game.Workspace.CurrentCamera for i = 1,10 do wait() 
		camera.CoordinateFrame = camera.CoordinateFrame * CFrame.new(0,2,0) wait() 
		camera.CoordinateFrame = camera.CoordinateFrame * CFrame.new(0,-2,0) end end

CameraIn.OnClientEvent:Connect(function(plr,Position,Focus,Time)
	print(1)
	
			local cam = game.Workspace.CurrentCamera
	        cam.CameraType = Enum.CameraType.Scriptable
	        cam:Interpolate(Position,Focus,Time)
	        print(4)
            shake()
	        script.Sound:Play()
			
end)


PlayerCamera.OnClientEvent:Connect(function()
	local camera = game.Workspace.CurrentCamera
	script.Sound:Stop()
	camera.CameraType = Enum.CameraType.Custom

end)

this is from original client snippet

this is from original server snippet

Yup I certainly shouldn’t be awake that much of a time, though it changed nothing

1 Like

It has the same issue nothing has changed^^