because its essential for my gun system so that people can see what other people are aiming at
Alright so basically how I made these type of systems are:
- Do the math calculations client side.
- Send that information to the server via Remote Event.
- Set everything on the server.
This is a general idea of how I get mine working, I would just DM you the rewritten code, but I’m not on pc at the moment sorry.
Already tried that, but the variables just don’t ever wanna line up with their names that were given on the client side
First step, create a “RemoteEvent” in “ReplicatedStorage” and name said event “BodyToMouseCFrameEvent.”
Client Script:
--/// Services:
local ReplicatedStorage = game:GetServices('ReplicatedStorage');
local PlayerService = game:GetService('Players');
local RunService = game:GetService('RunService');
--/// Constants:
local Camera = Workspace.CurrentCamera;
--// Player:
local LocalPlayer = PlayerService.LocalPlayer;
local Mouse = LocalPlayer:GetMouse();
--// Character:
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait();
local RootPart = Character:WaitForChild('HumanoidRootPart');
local Humanoid = Character:WaitForChild('Humanoid');
local Torso = Character:WaitForChild('Torso');
local Neck = Torso:WaitForChild('Neck');
local LeftShoulder = Torso:WaitForChild('Left Shoulder');
local RightShoulder = Torso:WaitForChild('Right Shoulder');
--// Instances:
local RemoteEvent = ReplicatedStorage:WaitForChild('BodyToMouseCFrameEvent');
--/// Variables:
local NeckC0, NeckC1 = Neck.C0, Neck.C1;
--/// Local Functions:
local BodyToMouseCFrame = function()
local MouseLookVector, HitPosition = Mouse.Origin.LookVector, Mouse.Hit.Position;
local Kek = CFrame.Angles(0, 0, math.asin(MouseLookVector.Y));
local RightPosition = RC1 * Kek:inverse();
local LeftPosition = LC1 * Kek:inverse();
return RemoteEvent:FireServer(MouseLookVector, HitPosition, RightPosition, LeftPosition);
end;
--/// Connections:
RunService.RenderStepped:Connect(BodyToMouseCFrame);
Server Script:
--/// Services:
local ReplicatedStorage = game:GetServices('ReplicatedStorage');
--/// Constants:
--// Instances:
local RemoteEvent = ReplicatedStorage:WaitForChild('BodyToMouseCFrameEvent');
--/// Local Functions:
local BodyToMouseCFrame = function(Player, LookVector, HitPosition, RightPosition, LeftPosition))
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait();
local RootPart = Character:WaitForChild('HumanoidRootPart');
local Humanoid = Character:WaitForChild('Humanoid');
local Torso = Character:WaitForChild('Torso');
local Neck = Torso:WaitForChild('Neck');
local LeftShoulder = Torso:WaitForChild('Left Shoulder');
local RightShoulder = Torso:WaitForChild('Right Shoulder');
Humanoid.AutoRotate = false;
RightShoulder.C1, LeftShoulder.C1 = RightPosition, LeftPosition;
Neck.C0 *= CFrame.Angles(math.asin(LookVector.Y), 0, 0):inverse();
RootPart.CFrame = CFrame.lookAt(RootPart.Position, Vector3.new(HitPosition.X, RootPart.Position.Y, HitPosition.Z), RootPart.CFrame.UpVector);
end;
Use this resource made by clonetrooper, it’s lightweight, works for all tools, shows hands and view model, basically everything if you want something realistic with tools, environment, etc.
Yes, tools follow with camera same with body, server and client side. Very performant friendly for what it does.
If you read the original code, it’s not setting the “body” in relation to the camera, it’s actually to the mouse position. That’s what my rewrite was for.
You will need to fire a remote event when you do changes in the client that are not replicated to the server, if you wish to do so
I already explained that, but they’ve had issues transitioning from client to server, so I just rewrote the code in the end for them.
slight issue
Yellow highlight doesn’t need to be bad, it’s just roblox suggesting something, have you tested the script first?
And what does “Find All” say that the highlight is for?
i need the neck.c0
doesnt work
Never read your code, was giving a resource that already did what post asked for and more.
I’m having problems with variables…
can someone please help me…
[character limit]
I tried to fix it, no more orange lines under it but now my character keeps rubberbanding up and down in the air, and when i dropped to the ground, i couldn’t walk.
--/// Services:
local ReplicatedStorage = game:GetService('ReplicatedStorage');
--/// Constants:
--// Instances:
local RemoteEvent = ReplicatedStorage:WaitForChild('BodyToMouseCFrameEvent');
--/// Local Functions:
local BodyToMouseCFrame = function(Player: Player, LookVector: Vector3, Position: Vector3, Kek: CFrame, RC0, RC1, LC0, LC1, NeckC0)
local Character = Player.Character or Player.CharacterAdded:Wait();
local RootPart = Character:WaitForChild('HumanoidRootPart');
local Humanoid = Character:WaitForChild('Humanoid');
local Torso = Character:WaitForChild('Torso');
local Neck = Torso:WaitForChild('Neck');
local LeftShoulder = Torso:WaitForChild('Left Shoulder');
local RightShoulder = Torso:WaitForChild('Right Shoulder');
RightShoulder.C1, LeftShoulder.C1 = RC1 * Kek:Inverse(), LC1 * Kek;
Neck.C0 = NeckC0 * CFrame.Angles(math.asin(LookVector.Y), 0, 0):Inverse();
RootPart.CFrame = CFrame.lookAt(RootPart.Position, Vector3.new(Position.X, RootPart.Position.Y, Position.Z), RootPart.CFrame.UpVector);
end;
RemoteEvent.OnServerEvent:Connect(BodyToMouseCFrame)
Technically works though…
can you actually answer me please
How is it looking?
(Chars Chars Chars)
Thank god you responded…
Read the message above!
Just a problem of rubberbanding and I don’t know how to fix it.