Events confusing camera for plr

So whenever I am currently writing a script that fires a rocket whenever the play presses E. Which fires an event over to the server with the current camera. But for some reason it confuses the camera with the player? I can’t find out why this is the case so if you could please help me!

Local Script:

-- Variables/Services --

local UIS = game:GetService("UserInputService")
local plr = game.Players.LocalPlayer
local remoteEvent = game.ReplicatedStorage.Events.rocketFired

-- Events --

UIS.InputBegan:Connect(function(input, GPS)
    if GPS then return end
    
    if input.KeyCode == Enum.KeyCode.E then
        local camera = workspace.CurrentCamera
        
        remoteEvent:FireServer(plr, camera)
        print("fired rocket event")
    end
end)

Server Script:

-- Variables/Services --

local RS = game:GetService("ReplicatedStorage")
local UIS = game:GetService("UserInputService")
local remoteEvent = RS.Events.rocketFired


-- Events --

remoteEvent.OnServerEvent:Connect(function(plr, camera)
    print("rocket event recieved")
    local rocket = Instance.new("Part", workspace)
    rocket.Position = camera.CFrame.LookVector
    rocket.Anchored = true
    rocket.CanCollide = false
end)

Instead of passing the CurrentCamera instance use pass the currentcamera.CFrame

UIS.InputBegan:Connect(function(input, GPS)
    if GPS then return end
    
    if input.KeyCode == Enum.KeyCode.E then
        local cameraCF = workspace.CurrentCamera.CFrame
        
        remoteEvent:FireServer(plr, cameraCF)
    end
end)
remoteEvent.OnServerEvent:Connect(function(plr, cameraCF)
    local rocket = Instance.new("Part", workspace)
    rocket.CFrame = cameraCF
    rocket.Anchored = true
    rocket.CanCollide = false
end)

But its still confusing the player for the camera. Thats the main issue

When you fire a RemoteEvent, you do not need to send the Player in the parameter list. When OnServerEvent is called, the first parameter will ALWAYS be the player who fired it

You simply need to do:

remoteEvent:FireServer(camera.CFrame)
1 Like

ahh yes I totally missed the point thats wrong xd

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