Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

I'm making a gun with animations and I'm having mutliple problems, help?

I'm making a gun, and decided to add animations and make the player's arms follow the mouse. I have a problem and a question.

Firstly, I'm having a weird problem, I have the gun, but when I duplicate it, the second one's "follow camera" system doesn't work.. Here's the code

local plr = game.Players.LocalPlayer

repeat wait() until game.Players.LocalPlayer.Character
local char1 = plr.Character
local Anim = char1.Humanoid:LoadAnimation(script.Parent.Idle)

local RightArm = char1.Torso["Right Shoulder"].C0
local LeftArm = char1.Torso["Left Shoulder"].C0
local Neck = char1.Torso["Neck"].C0

local ChangeVariable = false

repeat wait() until game.Players.LocalPlayer.Character

local char = plr.Character
local m = plr:GetMouse()

game["Run Service"].RenderStepped:Connect(function()
	
	if script.Parent.BoolEquipped.Value == true then
		
		local c = game.Workspace.CurrentCamera
		char.Torso["Right Shoulder"].C0 = CFrame.new(1,0.5,0) * CFrame.Angles(-math.asin((m.Origin.p - m.Hit.p).unit.y),1.55,0)
		char.Torso["Left Shoulder"].C0 = CFrame.new(-1,0.5,0) * CFrame.Angles(-math.asin((m.Origin.p - m.Hit.p).unit.y),-1.55,0)
		char.Torso["Neck"].C0 = CFrame.new(0,1,0) * CFrame.Angles(-math.asin((m.Origin.p - m.Hit.p).unit.y) + 1.55,3.15,0)
		
	else
		
		local c = game.Workspace.CurrentCamera
		char.Torso["Right Shoulder"].C0 = RightArm
		char.Torso["Left Shoulder"].C0 = LeftArm
		char.Torso["Neck"].C0 = Neck

	end

end)

script.Parent.Unequipped:Connect(function()
	
	char.Torso["Right Shoulder"].C0 = CFrame.new(0,0,0)
	char.Torso["Left Shoulder"].C0 = CFrame.new(0,0,0)
	char.Torso["Neck"].C0 = CFrame.new(0,0,0)
	
end)

script.Parent.Equipped:Connect(function()
	
	Anim:Play()
	
end)

script.Parent.Unequipped:Connect(function()
	
	Anim:Stop()
	
end)

I also have a question, does anyone know how can I make it so that the character's arms follow the mouse, but in a server script?

7 comments

0

Use a remote event to fire from server to client, cuz there is no way to make arms move with a server script, as you cannot get the local player

0

and i dont get wht u mean by: Firstly, I'm having a weird problem, I have the gun, but when I duplicate it, the second one's "follow camera" system doesn't work.. Here's the code

0

Lets say I have the gun, and I duplicate it (two have the same weapon two times), the new weapon (the clone) doesn't move the character's arms even though it's the exact same tool as the original one.

0

oh i get it. So can you tell me where the script is?

0

the script is inside the tool

0

ping

0

check reply on my answer

1 answer

It's not recommended to use a remote event to fire the mouse position to server, but if you want to do so, fire the mouse position every 0.5 seconds so it won't take your performance by a lot. The only downsides is it will take more performance than using local script to control head movement instead of remoting it to the server, and the head movement won't be smooth

2 comments

0

But are there any other ways of firing the mouse position to the server?

0

no there is not

This discussion is preserved as it was. New answers, comments, and votes are closed.