this is my scope in script,but it has a problem , the cframe part with the arms wont stop after the gun is aimed and i dont know how to cancel it out by putting a line of code after the tween 2 play line
if firstPerson and config:WaitForChild("Ironsight").Value then
animationTrack:Play()
local scope = script.Parent.Scope
scope["Meshes/sniper_scope"].Transparency= 0.1
scope.Part.Transparency = 0.97
scope.Part19.Transparency = 0.9
scope.Part19.Reflectance = 0.4
scope.Part.Reflectance = 0.4
local player = game.Players.LocalPlayer
local character = player.Character
if not character or not character.Parent then
character = player.CharacterAdded:wait()
end
local humanoid = character:WaitForChild("Humanoid")
local torso = character:WaitForChild("Torso")
local rightShoulder = torso:WaitForChild("Right Shoulder")
local leftShoulder = torso:WaitForChild("Left Shoulder")
local camera = game.Workspace.CurrentCamera
updateSpeed = 1
game:GetService("RunService").RenderStepped:Connect(function()
--character["Right Arm"].LocalTransparencyModifier = character["Right Arm"].Transparency
--character["Left Arm"].LocalTransparencyModifier = character["Left Arm"].Transparency
local camCF = camera.CoordinateFrame
local distance = (character.Head.Position - camCF.p).magnitude
if distance <= 1.01 and humanoid.Health ~= 0 and input.UserInputType == Enum.UserInputType.MouseButton2 then
rightShoulder.C0 = rightShoulder.C0:lerp((camCF * CFrame.new(1, -1, 0)):toObjectSpace(torso.CFrame):inverse() * CFrame.Angles(0, math.pi/2, 0), updateSpeed)
leftShoulder.C0 = leftShoulder.C0:lerp((camCF * CFrame.new(-1, -1, 0)):toObjectSpace(torso.CFrame):inverse() * CFrame.Angles(0, -math.pi/2, 0), updateSpeed)
else
rightShoulder.C0 = CFrame.new(1, 0.5, 0) * CFrame.Angles(0, math.pi/2, 0)
leftShoulder.C0 = CFrame.new(-1, 0, 0) * CFrame.Angles(0, -math.pi/2, 0)
end
end)
--zone
tween1:Play()
if config:WaitForChild("IronsightWalkSpeedReduce").Value then
humanoid.WalkSpeed = config:WaitForChild("IronsightWalkSpeed").Value
end
end
end
end)
UserInputService.InputEnded:Connect(function(input, gameProccesed)
if not gameProccesed or input.UserInputType == Enum.UserInputType.MouseButton2 then
tween2:Play()
--SOLUTION CODE HERE
animationTrack:Stop()
local scope = script.Parent.Scope
scope["Meshes/sniper_scope"].Transparency= 0
scope.Part.Transparency = 0
scope.Part19.Transparency = 0
scope.Part19.Reflectance = 1
scope.Part.Reflectance = 1
if config:WaitForChild("IronsightWalkSpeedReduce").Value then
humanoid.WalkSpeed = game:GetService("StarterPlayer").CharacterWalkSpeed
end
end
end)
function InputStarted(Input)
âyour code here
end)
function InputEnded(Input)
âyour code here
end)
UIS.InputBegan:Connect(InputStarted)
UIS.InputEnded:Connect(InputEnded)
this will call the corresponding function when the input start/ends. For example
function InputStarted(Input)
print(âStartâ)
end)
function InputEnded(Input)
print(âEndâ)
end)
UIS.InputBegan:Connect(InputStarted)
UIS.InputEnded:Connect(InputEnded)
In this code when a button is pressed it will print âStartâ and when you stop pressing the button it will print âEndâ.
but i have a question , it doesnt work in all tools , in my gun1 it works but in my gun2 in breaks , even though both guns give the error atempt to index nil with âDisconnectâ - Client - LocalScript:93
local player = game.Players.LocalPlayer
local character = player.Character
if not character or not character.Parent then
character = player.CharacterAdded:wait()
end
local humanoid = character:WaitForChild("Humanoid")
local torso = character:WaitForChild("Torso")
local rightShoulder = torso:WaitForChild("Right Shoulder")
local leftShoulder = torso:WaitForChild("Left Shoulder")
local RunS = game:GetService("RunService")
local connection
local TweenService = game:GetService("TweenService")
local tool = script.Parent
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local UserInputService = game:GetService("UserInputService")
local config = tool:WaitForChild("Configuration")
local remotes = tool:WaitForChild("Remotes")
local gunCursorIcon = "rbxasset://textures\\GunCursor.png"
local normalIcon = ""
local camera = workspace.CurrentCamera
local head = player.Character:WaitForChild("Head")
local animation = tool:WaitForChild("Animations"):WaitForChild("Aim")
local cameraTweenInfo = TweenInfo.new(
0.5,
Enum.EasingStyle.Sine,
Enum.EasingDirection.InOut,
0,
false,
0
)
local function isFirstPerson()
if (head.CFrame.p - camera.CFrame.p).Magnitude < 1.01 then
print(head)
return true
else
return false
end
end
local goal1 = {FieldOfView = config:WaitForChild("IronsightFov").Value}
local goal2 = {FieldOfView = 70}
local tween1 = TweenService:Create(camera, cameraTweenInfo, goal1)
local tween2 = TweenService:Create(camera, cameraTweenInfo, goal2)
local animationTrack = humanoid:LoadAnimation(animation)
UserInputService.InputBegan:Connect(function(input, gameProccesed)
if not gameProccesed and input.UserInputType == Enum.UserInputType.MouseButton2 then
local firstPerson = isFirstPerson()
if firstPerson and config:WaitForChild("Ironsight").Value then
animationTrack:Play()
local scope = script.Parent.Scope
scope["Meshes/sniper_scope"].Transparency= 0.1
scope.Part.Transparency = 0.97
script.Parent.Model.Iron.Transparency=0.97
script.Parent.Model.Iron2.Transparency=0.97
scope.Part19.Transparency = 0.9
scope.Part19.Reflectance = 0.4
scope.Part.Reflectance = 0.4
local camera = game.Workspace.CurrentCamera
updateSpeed = 1
connection = RunS.RenderStepped:Connect(function()
--character["Right Arm"].LocalTransparencyModifier = character["Right Arm"].Transparency
--character["Left Arm"].LocalTransparencyModifier = character["Left Arm"].Transparency
local camCF = camera.CoordinateFrame
local distance = (character.Head.Position - camCF.p).magnitude
if distance <= 1.01 and humanoid.Health ~= 0 and input.UserInputType == Enum.UserInputType.MouseButton2 then
rightShoulder.C0 = rightShoulder.C0:lerp((camCF * CFrame.new(1, -1, 0)):toObjectSpace(torso.CFrame):inverse() * CFrame.Angles(0, math.pi/2, 0), updateSpeed)
leftShoulder.C0 = leftShoulder.C0:lerp((camCF * CFrame.new(-1, -1, 0)):toObjectSpace(torso.CFrame):inverse() * CFrame.Angles(0, -math.pi/2, 0), updateSpeed)
end
end)
--zone
tween1:Play()
if config:WaitForChild("IronsightWalkSpeedReduce").Value then
humanoid.WalkSpeed = config:WaitForChild("IronsightWalkSpeed").Value
end
end
end
end)
UserInputService.InputEnded:Connect(function(input, gameProccesed)
if not gameProccesed or input.UserInputType == Enum.UserInputType.MouseButton2 then
tween2:Play()
connection:Disconnect()
rightShoulder.C0 = CFrame.new(1, 0.5, 0) * CFrame.Angles(0, math.pi/2, 0)
leftShoulder.C0 = CFrame.new(-1, 0.5, 0) * CFrame.Angles(0, -math.pi/2, 0)
animationTrack:Stop()
local scope = script.Parent.Scope
scope["Meshes/sniper_scope"].Transparency= 0
scope.Part.Transparency = 0
script.Parent.Model.Iron.Transparency=0
script.Parent.Model.Iron2.Transparency=0
scope.Part19.Transparency = 0
scope.Part19.Reflectance = 1
scope.Part.Reflectance = 1
if config:WaitForChild("IronsightWalkSpeedReduce").Value then
humanoid.WalkSpeed = game:GetService("StarterPlayer").CharacterWalkSpeed
end
end
end)