How can I move the enemy's camera?

sharinganRemote.OnServerEvent:Connect(function(player, rayStart, rayDirection)
	local character = player.Character
	local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
	local humanoid = character:WaitForChild("Humanoid")

	local raycastParams = RaycastParams.new()
	raycastParams.FilterType = Enum.RaycastFilterType.Exclude
	raycastParams.FilterDescendantsInstances = {character}

	local raycastResult = workspace:Raycast(rayStart, rayDirection, raycastParams)

	local sharinganVfx = ReplicatedStorage:WaitForChild("Vfx"):WaitForChild("SharinganVfx"):Clone()
	sharinganVfx.Parent = workspace.AbilitiesCloned
	sharinganVfx.CFrame = character.Head.CFrame * CFrame.new(0, 2, -5)

	wait(0.001)
	sharinganVfx.Attachment.ParticleEmitter:Emit(1)

	print("event")

	if raycastResult then
		local hitPart = raycastResult.Instance
		print(hitPart)
		if hitPart.Parent:FindFirstChild("Humanoid") then
			local characterEnemy = hitPart.Parent
			local humanoidEnemy = characterEnemy:FindFirstChild("Humanoid")
			humanoidEnemy.WalkSpeed = 0

			local enemyAnimation = ReplicatedStorage:WaitForChild("Animations"):WaitForChild("SharinganEnemyAnimation")
			humanoidEnemy:LoadAnimation(enemyAnimation):Play()
			humanoidEnemy:TakeDamage(abilitySettings.Abilities[4].damage)

			local part = workspace.cameraSharingan
			moveCameraToPartEvent:FireClient(characterEnemy)

			wait(abilitySettings.Abilities[4].lifeTime)

			humanoidEnemy.WalkSpeed = 16
		end
	end
end)

So this is my script, and at the moment when a player attacks another player the other player (let’s call him the enemy) takes damage. But I also want the enemy to have a camera attached to the desk and he sees the “room” and then the camera goes back to the enemy. But it is necessary that the camera is attached only to the enemy. I tried to make an event, but faced with the problem that I do not know how to attach the camera just at the enemy. Not the player. Can you help me please

1 Like

I don’t get what you mean by saying:

But I also want the enemy to have a camera attached to the desk and he sees the “room” and then the camera goes back to the enemy.

What “desk”? What “room” is that? Please be more specific.

I want the player’s CFrame camera to become a partome, and vice versa.

I get that, but what “desk” and “room” are you talking about?

Anyways, you could fire a remote to the otherPlayer to change the camera cframe, something like this:

--//  THIS IS JUST AN EXAMPLE
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local camera = workspace.CurrentCamera

ReplicatedStorage:WaitForChild("RemoteEvent").OnClientEvent:Connect(function()
	camera.CameraType = Enum.CameraType.Scriptable
	local oldCFrame = camera.CFrame
	
	camera.CFrame = workspace.Desk.PrimaryPart.Attachment.WorldCFrame
	task.wait(1)
	
	camera.CameraType = Enum.CameraType.Custom
	camera.CFrame = oldCFrame
end)

This may be true, but at the moment I have the problem that the camera changes in the first player and not in the second (characterEnemy).

1 Like

You can use the hitPart to get the otherPlayer:

local otherPlayer = game.Players:GetPlayerFromCharacter(hitPart.Parent)

So, instead of doing this:

local characterEnemy = hitPart.Parent
-- ...
moveCameraToPartEvent:FireClient(characterEnemy) --// this is the character, not the player!

Do this:

local characterEnemy = hitPart.Parent
local otherPlayer = game.Players:GetPlayerFromCharacter(characterEnemy)
-- ...
moveCameraToPartEvent:FireClient(otherPlayer)
2 Likes