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

Need help with my aiming script! the other arm is doing weird things!????

I tried to make that the other arm can move but it's making weird things instand

repeat wait() until workspace:findFirstChild(game.Players.LocalPlayer.Name)
wait()

local cam = workspace.CurrentCamera
local player = game.Players.LocalPlayer
local char = player.Character
local hastool = false
local armweld = player.Character.Torso["Right Shoulder"]
local origarmweldcf = armweld.C0
local basearmweldcf = origarmweldcf + Vector3.new(0,0.25,-0.25)
local baseheadweldcf = char.Torso.Neck.C1
local heading, attitude, bank

local cam2 = workspace.CurrentCamera
local player2 = game.Players.LocalPlayer
local char2 = player.Character
local hastool2 = false
local armweld2 = player.Character.Torso["Left Shoulder"]
local origarmweldcf2 = armweld.C0
local basearmweldcf2 = origarmweldcf + Vector3.new(0,-0.25,0.25)
local baseheadweldcf2 = char.Torso.Neck.C1
local heading, attitude, bank

function holdingtool()
	for _,instance in ipairs(char:GetChildren()) do
		if instance:IsA("Tool") then
			return true
		end
	end
end

cam.Changed:connect(function()	
	
	local sx, sy, sz, m00, m01, m02, m10, m11, m12, m20, m21, m22 = cam.CoordinateFrame:components()
	heading = math.atan2(m02, m22)
	attitude = math.asin(-m12)
	bank = math.atan2(m10, m11)
	
	if hastool then
		armweld.C0 = basearmweldcf*CFrame.Angles(0,0,attitude)
	end
	
	char.Torso.Neck.C1 = baseheadweldcf*CFrame.Angles(attitude,0,0)

	local sx, sy, sz, m00, m01, m02, m10, m11, m12, m20, m21, m22 = cam.CoordinateFrame:components()
	heading = math.atan2(m02, m22)
	attitude = math.asin(-m12)
	bank = math.atan2(m10, m11)
	
	if hastool then
		armweld.C0 = basearmweldcf*CFrame.Angles(0,0,attitude)
	end
	
	char.Torso.Neck.C1 = baseheadweldcf*CFrame.Angles(attitude,0,0)
	
end)

char.ChildAdded:connect(function(child)
	if child:IsA("Tool") then
		hastool = true
		armweld.C0 = basearmweldcf*CFrame.Angles(0,0,attitude)
	end
end)

char.ChildAdded:connect(function(child)
	if child:IsA("Tool") then
		hastool = true
		armweld2.C0 = basearmweldcf*CFrame.Angles(0,0,attitude)
	end
end)

char.ChildRemoved:connect(function()
	wait()
	if not holdingtool() then
		hastool = false
		armweld.C0 = origarmweldcf
	end
end)

char.ChildRemoved:connect(function()
	wait()
	if not holdingtool() then
		hastool = false
		armweld2.C0 = origarmweldcf
	end
end)

1 comment

0

please help!!

1 answer

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