I'm having trouble replicating the flashlight to the server

local script

local player = game.Players.LocalPlayer
local char = player.Character
local cam = workspace.CurrentCamera
local viewmodel = game.ReplicatedStorage.VmStorage:WaitForChild(“Flashlight”):Clone() or game.ReplicatedStorage.VmStorage.Flashlight:Clone() – just incase it’s already loaded
viewmodel.Parent = game.ReplicatedStorage.VmStorage[“ClonedVm’s”]
local run = game:GetService(“RunService”)
local CameraCF = CFrame.new()
local swayCF = CFrame.new()
local SwayX = 3
local SwayY = 5
local equip = game.ReplicatedStorage.BoolStorage.Flashlight
local uis = game:GetService(“UserInputService”)
task.wait()
local audio = script[“Flashlight Click”]
uis.InputBegan:Connect(function(inp)
if inp.KeyCode == Enum.KeyCode.F then
print(“alive”)
flashlight()

end	

end)

function flashlight()
local val = game.ReplicatedStorage.BoolStorage.StartupGui.InGui
if val.Value == false then
if equip.Value == false then
changeIfSwitch()
viewmodel.Handle[“Right Arm”].Color = game.Players.LocalPlayer.Character:WaitForChild(“Right Arm”).Color
viewmodel.Parent = cam
game.Players.LocalPlayer.Character:WaitForChild(“Right Arm”).Transparency = 1
audio:Play()
equip.Value = true
run.RenderStepped:Connect(function()
if game.Players.LocalPlayer.Character:WaitForChild(“Humanoid”).Health > 0 then
local rotation = workspace.CurrentCamera.CFrame:toObjectSpace(CameraCF)
local x,y,z = rotation:ToOrientation()
swayCF = swayCF:Lerp(CFrame.new(math.sin(-y)*SwayX,math.sin(x)*SwayY,0), .2)
CameraCF = cam.CFrame
local headCF = player.Character:WaitForChild(“Head”).CFrame
game.ReplicatedStorage.EventStorage.SecondaryFlashlightEvents.on:FireServer(swayCF,SwayX,SwayY,cam,CameraCF,headCF,viewmodel)
end
end)
else
equip.Value = false
viewmodel.Parent = game.ReplicatedStorage.VmStorage[“ClonedVm’s”]
game.Players.LocalPlayer.Character:WaitForChild(“Right Arm”).Transparency = 0
audio:Play()
end
end
end

function hideFlashlightIfDead()
if game.Players.LocalPlayer.Character:WaitForChild(“Humanoid”).Health <= 0 then
equip.Value = false
viewmodel.Parent = game.ReplicatedStorage.VmStorage[“ClonedVm’s”]
game.Players.LocalPlayer.Character:WaitForChild(“Right Arm”).Transparency = 0
end
end

function changeIfSwitch()
if game.ReplicatedStorage.BoolStorage.ThirdPerson.Switch.Value == true then
SwayX = 1
else
SwayX = 2.5
end
end

server script

game.ReplicatedStorage.EventStorage.SecondaryFlashlightEvents.on.OnServerEvent:Connect(function(plr:Player,NUL,swayCF,SwayX,SwayY,cam,CameraCF,headCF,viewmodel)

headCF = plr.Character:WaitForChild(“Head”).CFrame

–CameraCF = cam

viewmodel:SetPrimaryPartCFrame(headCF * CFrame.new(CameraCF.Rotation.X,CameraCF.Rotation.Y,CameraCF.Rotation.Z) * CFrame.new(-0.6,-0.4,0.7)*swayCF)

end)

my problem is with the server script if you take the setprimarypartcframe code and put it in the local it works fine but in server it says invalid argument #2 (Vector3 expected, got number) am i doing something wrong

2 Likes

At what line does it give this error? It would make it easier for us to solve the problem without having to understand the entire script.

Sorry i posted this at 12am so i fell asleep it errors on the server

viewmodel:SetPrimaryPartCFrame(headCF * CFrame.new(CameraCF.Rotation.X,CameraCF.Rotation.Y,CameraCF.Rotation.Z) * CFrame.new(-0.6,-0.4,0.7)*swayCF)

on the server it tells me that it expects a vector3 and not a number but if you put that exact same line of code and put it into the local script it works

I don’t know the problem with the code. Might be a bug?

im not sure because locally it works fine but server wise it breaks

Could be because of the fact that you’re using the Camera.Rotation x,y,z which from your code would be a rotation instead of a position. When you’re creating a CFrame using CFrame.new() it requires a position, to apply a rotation you would need to use something like :

CFrame.new(Vector3) * CFrame.Angles(R1,R2,R3)

Not sure though, try removing some of the CFrame.new() functions and see if any specific one is causing the issue.

didnt work still says the same thing

prob because you’re multiplying a cframe with a number which is swayCF

Then why does it work fine locally

I have a feeling that this is a DOORS script.

Also, it works fine locally because it has to do with the camera I am pretty sure.

it is not i made it from scratch but i did refrence it off an old flashlight script that i stole from the toolbox when i first started roblox studio

im kinda confused because im not getting an error anymore but it still doesnt work

headCF = plr.Character:WaitForChild(Head).CFrame
–CameraCF = cam
CamCFRot = CameraCF.Rotation
local SwayX = 3
local SwayY = 5
local swayCF = CFrame.new()
local v3 = Vector3.new(CameraCF.Rotation.XVector,CameraCF.Rotation.YVector,CameraCF.Rotation.ZVector)
local rotation = cam:toObjectSpace(CameraCF)
local x,y,z = rotation:ToOrientation()
local swayCF = swayCF:Lerp(CFrame.new(math.sin(-y)*SwayX,math.sin(x)*SwayY,0), .2)
viewmodel = game.ReplicatedStorage.VmStorage.Flashlight or cam.Flashlight
viewmodel:SetPrimaryPartCFrame(headCF * CFrame.new(v3) * CFrame.new(-0.6,-0.4,0.7) * swayCF)