Variables switching in remote events?

So i’m trying to change the cframe of a camera when this ai monster hits the player, so im firing a client from the enemy ai script.

the problem is one of the variables is being swapped, and the other is returning nil.

small section of server script:

if debounce == false then
			debounce = true
			
			print(plr)		-- coming back my name	(plr)
			print(target)	--coming back my name	(character)
			jumpscareremote:FireClient(plr, script.Parent.ScareCam)
			npc.Head.AttackSound:Play()
			walkAnim:Stop()
			attackAnim:Play()
			target.Humanoid.Health -= DAMAGE
			task.wait(0.5)
			walkAnim:Play()
			debounce = false
		end

local script:

local rs = game:GetService("ReplicatedStorage")
local remote = rs:WaitForChild("jumpscare")
local camera = workspace.CurrentCamera

remote.OnClientEvent:Connect(function(plr, jumpscareCamera)
	
	print(plr)			--coming back the name of jumpscareCamera
	print(jumpscareCamera)	-- coming back nil
	
	camera.CFrame = jumpscareCamera.CFrame
	
end)

ive had this problem before and i tried to see how i fixed it before, but it was less similar then i thought it was.

The first argument of :FireClient() just tells the remote who to fire the remote to, it is not actually passing a variable, try changing it to

jumpscareremote:FireClient(plr, plr, script.Parent.ScareCam)

Or just getting the player from the local script

local plr = game.Players.LocalPlayer
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.