#inputbegan running twice

104 messages · Page 1 of 1 (latest)

still bluff
#
UserInputService.InputBegan:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.Q then
        print("ran")
        if isLockOnEnabled == false then
            isLockOnEnabled = true
            local hint = script.Hint:Clone()
            hint.Text = "Aimlock has been enabled."
            hint.Parent = player.PlayerGui.Hints.Frame
            wait(2)
            ts:Create(hint,info,{ TextTransparency = 1 }):Play()
            wait(1)
            hint:Destroy()
        elseif isLockOnEnabled == true then
            isLockOnEnabled = false
            lockOn = nil
            local hint = script.Hint:Clone()
            hint.Text = "Aimlock has been disabled."
            hint.Parent = player.PlayerGui.Hints.Frame
            wait(2)
            ts:Create(hint,info,{ TextTransparency = 1 }):Play()
            wait(1)
            hint:Destroy()
        end
    end
end)

why does this run twice on one key press?
i have another script nearly identical to this but it doesn't run into this problem

uis.InputBegan:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.Q and not Chatting() then
        if esp == false then
            esp = true
            local hint = script.Hint:Clone()
            hint.Text = "ESP has been enabled."
            hint.Parent = plr.PlayerGui.Hints.Frame
            wait(2)
            ts:Create(hint,info,{ TextTransparency = 1 }):Play()
            wait(1)
            hint:Destroy()
        else
            esp = false
            local hint = script.Hint:Clone()
            hint.Text = "ESP has been disabled."
            hint.Parent = plr.PlayerGui.Hints.Frame
            wait(2)
            ts:Create(hint,info,{ TextTransparency = 1 }):Play()
            wait(1)
            hint:Destroy()
        end
    end
end)
willow vessel
still bluff
#

the problem only occurs with one of the scripts the aimlock one

#

when i disable all other functionality, the esp script only prints "ran" once per key press

#

but the other script does it twice for one press

#

ive tried to look online ask chatgpt etc i cant find a fix

willow vessel
#

maybe problem in check?

#

or in your keyboard

#

because

#

its works very well for me

still bluff
#

or i mean ik what u mean

#

but

#

as i said it works just fine for the other script

willow vessel
#

Well, maybe there is a key pressed 2 times

still bluff
willow vessel
#

OH

#

WAIT

#
UserInputService.InputBegan:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.Q then
        print("ran")
        if isLockOnEnabled == false then
            isLockOnEnabled = true
            local hint = script.Hint:Clone()
            hint.Text = "Aimlock has been enabled."
            hint.Parent = player.PlayerGui.Hints.Frame
            wait(2)
            ts:Create(hint,info,{ TextTransparency = 1 }):Play()
            wait(1)
            hint:Destroy()
        else
            isLockOnEnabled = false
            lockOn = nil
            local hint = script.Hint:Clone()
            hint.Text = "Aimlock has been disabled."
            hint.Parent = player.PlayerGui.Hints.Frame
            wait(2)
            ts:Create(hint,info,{ TextTransparency = 1 }):Play()
            wait(1)
            hint:Destroy()
        end
    end
end)
#

try to use this

still bluff
#

may i ask what you changed?

willow vessel
#

elseif to "else"

still bluff
#

i already tried that

#

but my friend changed it

#

that was what i used originally

#

if you thought that it runs twice because it changes the value to false/true and then runs the other if statement then that's wrong, the text is the same for both hints

#

the timecodes are the exact same for both aswell

clear falcon
#

still with the problem¿?

still bluff
#

been on this for like the past 40 ish minutes

willow vessel
#

I have no assumptions, but I am sure that the problem is in the check.

still bluff
#

"ran" prints twice even when outside the checks

#

it was the 1st line after UserInputService.InputBegan:Connect(function(input) but it still occurs

#

like this

#

i tried disabling every script that i have in my game aswell

#

apart from this

#

still doesnt work

clear falcon
#

well, i test it and only run once

#

make sure u have only that script created

#

can i see the whole localscript tho?

still bluff
#
--local Camera = workspace.CurrentCamera
--Camera.CameraType = Enum.CameraType.Custom
--local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
-- local ownTorso = nil
local lockOn = nil
local isLockOnEnabled = false
local ts = game:GetService("TweenService")
local info = TweenInfo.new(1,Enum.EasingStyle.Linear)

--[[
local smoothness = player:WaitForChild("aimlock_smooth").Value

player.aimlock_smooth.Changed:Connect(function()
    smoothness = player:WaitForChild("aimlock_smooth").Value
end)


local function toggleLockOn()
end


function notBehindWall(target)
    local ray = Ray.new(player.Character.Head.Position, (target.Position - player.Character.Head.Position).Unit * 300)
    local part, position = game:GetService("Workspace"):FindPartOnRayWithIgnoreList(ray, {player.Character}, false, true)
    if part then
        local humanoid = part.Parent:FindFirstChildOfClass("Humanoid")
        if not humanoid then
            humanoid = part.Parent.Parent:FindFirstChildOfClass("Humanoid")
        end
        if humanoid and target and humanoid.Parent == target.Parent then
            local pos, visible = Camera:WorldToScreenPoint(target.Position)
            if visible then
                return true
            end
        end
    end
end


function getPlayerClosestToMouse()
    local target = nil
    local maxDist = 500
    local mouse = player:GetMouse()
    local players = game.Players
    for _,v in pairs(players:GetPlayers()) do
        if v.Character then
            if v.Character:FindFirstChild("Humanoid") and v.Character.Humanoid.Health ~= 0 and v.Character:FindFirstChild("HumanoidRootPart") and v.TeamColor ~= player.TeamColor then
                local pos, vis = Camera:WorldToViewportPoint(v.Character.HumanoidRootPart.Position)
                local dist = (Vector2.new(mouse.X, mouse.Y) - Vector2.new(pos.X, pos.Y)).magnitude
                if dist < maxDist and vis then
                    local torsoPos = Camera:WorldToViewportPoint(v.Character.HumanoidRootPart.Position)
                    local torsoDist = (Vector2.new(mouse.X, mouse.Y) - Vector2.new(torsoPos.X, torsoPos.Y)).magnitude
                    local headPos = Camera:WorldToViewportPoint(v.Character.Head.Position)
                    local headDist = (Vector2.new(mouse.X, mouse.Y) - Vector2.new(headPos.X, headPos.Y)).magnitude
                    if torsoDist > headDist then
                        if notBehindWall(v.Character.Head) then
                            target = v.Character.Head
                        end
                    else
                        if notBehindWall(v.Character.HumanoidRootPart) then
                            target = v.Character.HumanoidRootPart
                        end
                    end
                    maxDist = dist
                end
            end
        end
    end
    return target
end
--]]

UserInputService.InputBegan:Connect(function(input)
    print("ran")
    if input.KeyCode == Enum.KeyCode.Q then
        if isLockOnEnabled == false then
            isLockOnEnabled = true
            local hint = script.Hint:Clone()
            hint.Text = "Aimlock has been enabled."
            hint.Parent = player.PlayerGui.Hints.Frame
            wait(2)
            ts:Create(hint,info,{ TextTransparency = 1 }):Play()
            wait(1)
            hint:Destroy()
        else
            isLockOnEnabled = false
            lockOn = nil
            local hint = script.Hint:Clone()
            hint.Text = "Aimlock has been disabled."
            hint.Parent = player.PlayerGui.Hints.Frame
            wait(2)
            ts:Create(hint,info,{ TextTransparency = 1 }):Play()
            wait(1)
            hint:Destroy()
        end
    end
end)
clear falcon
#

number of lines in the code¿?

still bluff
#
--[[
RunService.RenderStepped:Connect(function()
    if isLockOnEnabled then
        local closestPlayer = getPlayerClosestToMouse()
        if closestPlayer then
            lockOn = closestPlayer
        else
            lockOn = nil
        end

        if lockOn then

            local desiredCFrame = CFrame.lookAt(Camera.CFrame.Position, lockOn.Position)
            Camera.CFrame = desiredCFrame
        end
    end
end)

player.CharacterAdded:Connect(function(char)
    ownTorso = char:WaitForChild("HumanoidRootPart")
    char.Humanoid.Died:Connect(function()
        lockOn = nil
    end)
end)
--]]
#

i commented the rest

#

to try to narrow down the problem

clear falcon
#

test it, only prints once

#

just look all the scripts u got and make sure abt everything

still bluff
still bluff
#

so idk

clear falcon
#

another script i mean

willow vessel
#

its because

still bluff
willow vessel
#

you do print under inputbegan

#

and didn't checked keycode

still bluff
still bluff
#

i said i tried both versions already

clear falcon
#

anyway will print only one time if it put over the inputbegan

#

why inputbegan will prints twice when press one time

willow vessel
#

I can't help, I don't see any problems in the code, sorry.

clear falcon
#

are you very SURE that aint another thing messing up?

willow vessel
#

Everything works fine for me too

clear falcon
#

or send a video idk

#

and show

#

where does the prints comes

still bluff
#

i feel like if i moved the exact same code from ESP script into here it would still print twice

#

EVERY script has been disabled

#

the problem still occurs

clear falcon
#

well

#

click into all the prints

#

and see if it gots u to a diff script

#

idk

still bluff
#

it doesnt

clear falcon
#

because u're not playing

#

play and click on them

willow vessel
#
UserInputService.InputBegan:Connect(function(input)
    print("ran")
    if input.KeyCode == Enum.KeyCode.Q and isLockOnEnabled == false then
            isLockOnEnabled = true
            local hint = script.Hint:Clone()
            hint.Text = "Aimlock has been enabled."
            hint.Parent = player.PlayerGui.Hints.Frame
            wait(2)
            ts:Create(hint,info,{ TextTransparency = 1 }):Play()
            wait(1)
            hint:Destroy()
        elseif input.KeyCode == Enum.KeyCode.Q and isLockOnEnabled == true then
            isLockOnEnabled = false
            lockOn = nil
            local hint = script.Hint:Clone()
            hint.Text = "Aimlock has been disabled."
            hint.Parent = player.PlayerGui.Hints.Frame
            wait(2)
            ts:Create(hint,info,{ TextTransparency = 1 }):Play()
            wait(1)
            hint:Destroy()
        end
    end
end)
#

i know this usseless

still bluff
#

this problem is literally unfixable i dont understand

clear falcon
still bluff
#

i will try making a whole new script and moving the code over there

clear falcon
#

no wait

#

delete the script

#

and press q

still bluff
#

yeah i was going to wait

#

nope

#

doesnt print anything after i deleted

#

yo

#

i fixed it

#

i justm oved all the code into a new script

#

xd

#

thats a studio bug then wow

#

but it happens ingame aswell

#

i tried it in roblox