Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

The remote event script is still not working and I don't know why. Help?

Asked by
icecar 13
4 years ago

Ive changed up the code a tiny bit but I don't know whats wrong.

Script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local HeadRotation = Instance.new("RemoteEvent")
HeadRotation.Parent = ReplicatedStorage
HeadRotation.Name = ("HeadRotation")

local function HeadRotationFired(player)
    local CFNew, CFAng, CFtoObjectSpace = CFrame.new, CFrame.Angles, CFrame.new( ).toObjectSpace
local asin, pi, hpi = math.asin, math.pi, math.pi / 2

local Plr= game.Players.LocalPlayer

    if Plr.Character then
        local Root, Neck, Humanoid, Camera = Plr.Character:FindFirstChild("HumanoidRootPart"), Plr.Character:FindFirstChild("Neck", true), Plr.Character:FindFirstChild("Humanoid"), workspace.CurrentCamera
        if Root and Neck and Humanoid and Camera.CameraSubject then
            local R6 = Humanoid.RigType == Enum.HumanoidRigType.R6
            if Camera.CameraSubject.Parent == Plr.Character then
                local CameraDirection = CFtoObjectSpace(Root.CFrame, Camera.CFrame).lookVector.unit
                Neck.C0 = CFNew(Neck.C0.p) * CFAng(0, -asin(CameraDirection.x), 0) * (R6 and CFAng(-hpi + asin(CameraDirection.y), 0, pi) or CFAng(asin(CameraDirection.y), 0, 0))
            else
                Neck.C0 = R6 and CFNew(Neck.C0.p) * CFAng(-hpi, 0, pi) or CFNew(Neck.C0.p)
            end
        end
    end
end

HeadRotation.OnServerEvent:Connect(HeadRotationFired)

Local script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local HeadRotation = ReplicatedStorage:WaitForChild("HeadRotation")

HeadRotation:FireServer()
0
Pls be more specific what isn't working royaltoe 5144 — 4y
0
There is no need to define the plr variable. Use the parameter player that gets passed automatically when a client communicates with a server. ForeverBrown 356 — 4y
0
You also can not get a localplayer on the server ForeverBrown 356 — 4y
0
Argument, not parameter DeceptiveCaster 3761 — 4y
0
many apologies ForeverBrown 356 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago

The server can't use LocalPlayer because the server isn't client-oriented.

In your server script, remove line 10 and replace lines 12 and 13 with this:

    if player.Character then
            local Root, Neck, Humanoid, Camera = player.Character:FindFirstChild("HumanoidRootPart"), player.Character:FindFirstChild("Neck", true), player.Character:FindFirstChild("Humanoid"), workspace.CurrentCamera

You may then replace line 16 with:

if Camera.CameraSubject.Parent == player.Character then

player is the name of the parameter used in your function to receive the player object argument passed by OnServerEvent.

0
For some reason its not working icecar 13 — 4y
0
Getting any errors? DeceptiveCaster 3761 — 4y
0
nope no errors. icecar 13 — 4y
0
R6 is a condition in your code. A condition evaluates to either true or false. DeceptiveCaster 3761 — 4y
View all comments (2 more)
0
So what do I need to changed icecar 13 — 4y
0
That argument. DeceptiveCaster 3761 — 4y
Ad

Answer this question