Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I need that with only 1 key pressed 2 times different things happen, can somebody help me?

Asked by 2 years ago

I want something to happen when I press the Q key and I want something else to happen when I press it again

LOCAL

local TWS = game:GetService("TweenService")
local input = game:GetService("UserInputService")

input.InputBegan:Connect(function(io, key)
    if io.KeyCode == Enum.KeyCode.Q then
        script.RemoteEvent:FireServer()
        script.Disabled = true
    end
end)


GLOBAL

local Event = script.Parent
local db = true
local Carpeta = script.Parent.Parent.FX
local User = game:GetService("UserInputService")
local Agarre = Instance.new("Weld")
local Hab = Carpeta:Clone()

Event.OnServerEvent:Connect(function(plr)
    local Torso = plr.Character.HumanoidRootPart
    Hab.Parent = workspace
    local Stand = Hab.Stando
    Agarre.Parent = Torso
    Agarre.Part0 = Torso
    Agarre.Part1 = Stand.HumanoidRootPart
    Agarre.C1 = CFrame.new(-3,-1.5,-2)

end)



0
You could set a variable like "local mode = 0" and when you press Q it checks what mode it is on. If it's on 0 then it does function1 and adds 1 to mode. Then when you press Q again, it checks the mode and if it's on 1 then it does function2 and minuses 1. KingDomas 153 — 2y

1 answer

Log in to vote
0
Answered by
pwx 1581 Moderation Voter
2 years ago

You could add a dictionary on the server in terms to check if it's already been pressed before or not.

local Dictionary = {}

local Players = game:GetService('Players')

Event.OnServerEvent:Connect(function(Player)
    if Dictionary[Player.Name] == true then
        Dictionary[Player.Name] = false
        local Torso = plr.Character.HumanoidRootPart
            Hab.Parent = workspace
         local Stand = Hab.Stando
         Agarre.Parent = Torso
         Agarre.Part0 = Torso
            Agarre.Part1 = Stand.HumanoidRootPart
            Agarre.C1 = CFrame.new(-3,-1.5,-2)
    elseif Dictionary[Player.Name] == false then
        Dictionary[Player.Name] = true
        -- do other stuff
    end -- dictionary check
end) -- onEvent

Players.PlayerAdded:Connect(function(Player)
    if not Dictionary[Player.Name] then
        Dictionary[Player.Name] = false
    end -- dictionary check
end)

Players.PlayerRemoving:Connect(function(Player)
    if Dictionary[Player.Name] then
        Dictionary[Player.Name] = nil
    end -- dictionary check
end) -- onRemoving
Ad

Answer this question