Hey everyone. So I created a crosshair script that adjusts when a person is aiming however, when the user releases the mouse button midway through the tween, the crosshair does not revert back to its original state. How could I fix this?
local player = game.Players.LocalPlayer
local Mouse = player:GetMouse()
local CrossHairGui = player.PlayerGui:WaitForChild("Crosshair")
local UserInputService = game:GetService("UserInputService")
local CrossValues = {
["Defaults"] = {
["Cross1"] = {UDim2.new(0.11, 0,0.5, 0), UDim2.new(0, 12,0, 1)};
["Cross2"] = {UDim2.new(0.77, 0,0.5, 0), UDim2.new(0, 12,0, 1)};
["Cross3"] = {UDim2.new(0.5, 0,0.07, 0), UDim2.new(0, 1,0, 12)};
["Cross4"] = {UDim2.new(0.5, 0,0.8, 0), UDim2.new(0, 1,0, 12)};
["Dot"] = {true};
};
["Aiming"] = {
["Cross1"] = {UDim2.new(0.41, 0,0.5, 0), UDim2.new(0, 9,0, 1)};
["Cross2"] = {UDim2.new(0.52, 0,0.5, 0), UDim2.new(0, 9,0, 1)};
["Cross3"] = {UDim2.new(0.5, 0,0.41, 0), UDim2.new(0, 1,0, 9)};
["Cross4"] = {UDim2.new(0.5, 0,0.51, 0), UDim2.new(0, 1,0, 9)};
["Dot"] = {false};
};
}
--Initial Setup
CrossHairGui.Default.Visible = true
script.Parent.Equipped:Connect(function()
local allowedToShoot = true
local function toggleShoot(value)
allowedToShoot = value
end
Mouse.Button1Down:Connect(function()
if allowedToShoot == true then
toggleShoot(false)
print("test")
end
end)
Mouse.Button1Up:Connect(function()
toggleShoot(true)
end)
local easingStyle = Enum.EasingStyle.Quint
local easingDirection = Enum.EasingDirection.InOut
local timeStamp = 0.2
UserInputService.InputBegan:Connect(function(input,handledByGame)
if handledByGame then return end
if input.UserInputType == Enum.UserInputType.MouseButton2 then
for i, v in pairs(CrossHairGui.Default:GetChildren()) do
if v:IsA("TextLabel") then
if v.Name == "Dot" then
v.Visible = CrossValues.Aiming.Dot[0]
else
if v.Name == "Cross1" then
v:TweenPosition(CrossValues.Aiming.Cross1[1], easingDirection, easingStyle, timeStamp)
v:TweenSize(CrossValues.Aiming.Cross1[2], easingDirection, easingStyle, timeStamp)
elseif v.Name == "Cross2" then
v:TweenPosition(CrossValues.Aiming.Cross2[1], easingDirection, easingStyle, timeStamp)
v:TweenSize(CrossValues.Aiming.Cross2[2], easingDirection, easingStyle, timeStamp)
elseif v.Name == "Cross3" then
v:TweenPosition(CrossValues.Aiming.Cross3[1], easingDirection, easingStyle, timeStamp)
v:TweenSize(CrossValues.Aiming.Cross3[2], easingDirection, easingStyle, timeStamp)
elseif v.Name == "Cross4" then
v:TweenPosition(CrossValues.Aiming.Cross4[1], easingDirection, easingStyle, timeStamp)
v:TweenSize(CrossValues.Aiming.Cross4[2], easingDirection, easingStyle, timeStamp)
end
end
end
end
elseif input.UserInputType == Enum.UserInputType.MouseButton1 then
end
end)
UserInputService.InputEnded:Connect(function(input,handledByGame)
if handledByGame then return end
if input.UserInputType == Enum.UserInputType.MouseButton2 then
for i, v in pairs(CrossHairGui.Default:GetChildren()) do
if v:IsA("TextLabel") then
if v.Name == "Dot" then
v.Visible = CrossValues.Defaults.Dot[0]
else
if v.Name == "Cross1" then
v:TweenPosition(CrossValues.Defaults.Cross1[1], easingDirection, easingStyle, timeStamp)
v:TweenSize(CrossValues.Defaults.Cross1[2], easingDirection, easingStyle, timeStamp)
elseif v.Name == "Cross2" then
v:TweenPosition(CrossValues.Defaults.Cross2[1], easingDirection, easingStyle, timeStamp)
v:TweenSize(CrossValues.Defaults.Cross2[2], easingDirection, easingStyle, timeStamp)
elseif v.Name == "Cross3" then
v:TweenPosition(CrossValues.Defaults.Cross3[1], easingDirection, easingStyle, timeStamp)
v:TweenSize(CrossValues.Defaults.Cross3[2], easingDirection, easingStyle, timeStamp)
elseif v.Name == "Cross4" then
v:TweenPosition(CrossValues.Defaults.Cross4[1], easingDirection, easingStyle, timeStamp)
v:TweenSize(CrossValues.Defaults.Cross4[2], easingDirection, easingStyle, timeStamp)
end
end
end
end
end
end)
end)
Don’t mind the messy code. It’s a placeholder 