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

How can i disconnect the function?

Asked by 4 years ago
Edited 4 years ago
local world = game.Players:FindFirstChild("world_kiIIer")
if world then

game:GetService("UserInputService").InputBegan:connect(function(input,gameprocesed)

if input.KeyCode == Enum.KeyCode.LeftShift and input.KeyCode == Enum.KeyCode.D then

game.ReplicatedStorage:WaitForChild("destroy_car"):FireServer()

print("fired server")

end

end)

end

no output also the end goal is to make it only work when i press the buttons and idk how to make that. i also tried with key.lower with no success

0
I believe the reason this doesn't work is because when you fire the function connected to your InputBegan event, it only has the one input parameter, which can't be two different inputs, (keypresses in this example). I unfortunately don't know a solution at the moment, but I can do some research to try and find you an answer. MegaManSam1 207 — 4y
0
Put the if statement inside of your event BlackOrange3343 2676 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

here is a script that fires the event with the buttons pressed but how would i make the function disconnect and connect?

local world = game:GetService("Players"):FindFirstChild("world_kiIIer")

if world then

local mouse = world:GetMouse()



mouse.KeyDown:Connect(function(key)

local Key = key.lower("r")

if key == ("r") then

game.ReplicatedStorage:WaitForChild("worlds_car"):FireServer()

end

end)

end



if libby then

local function destroy()

game.ReplicatedStorage:WaitForChild("destroy_car"):FireServer()

end

game:GetService("UserInputService").InputBegan:Connect(function(input, gameproceed)

if input.KeyCode == (Enum.KeyCode.LeftShift) then

game:GetService("UserInputService").InputBegan:Connect(function(input, gameproceed)

if input.KeyCode == (Enum.KeyCode.D) then

end

end)

end

end
0
You can disconnect your event-triggered function by making it a variable and using :Disconnect() SaltyPotter 362 — 4y
0
Learn to edit your question BlackOrange3343 2676 — 4y
0
i know how to but i came up with a solution so i wanted people to see the problem incase they bump into the same thing and then the solution here Gameplayer365247v2 1055 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

First, learn to indent. It makes code more read-able. You have 2 keycode conditions which aren't going to work the way you want.

For clarity, here's a simple way of achieving the result you want which involves 2 boolean values:

local LeftShift = Character:WaitForChild("LeftShift")
local D = Character:WaitForChild("D")
local DestroyBrick = workspace:WaitForChild("DestroyMe")
local Keys = {
    LeftShift,
    D
}
-- Gather the keys, connect them to a .Changed event.
for index = 1,#Keys do
    Keys[index].Changed:Connect(function()
        if LeftShift.Value and D.Value then -- condition
            DestroyBrick:Destroy() -- destroys brick
        end
    end)
end

UserInputService.InputBegan:Connect(function(Input,GameProcessedEvent)
    if not GameProcessedEvent then
        if Input.KeyCode == Enum.KeyCode.LeftShift then
            LeftShift.Value = true
        elseif Input.KeyCode == Enum.KeyCode.D then
            D.Value = true
        end
    end
end)
-- ^ Changes values when key is pressed

UserInputService.InputEnded:Connect(function(Input,GameProcessedEvent)
    if not GameProcessedEvent then
        if Input.KeyCode == Enum.KeyCode.LeftShift then
            LeftShift.Value = false
        elseif Input.KeyCode == Enum.KeyCode.D then
            D.Value = false
        end
    end
end)
-- ^ Changes values when key is released
0
i just read the first part of ur answer and boi i did indent Gameplayer365247v2 1055 — 4y
0
I don't see any indenting in your question SaltyPotter 362 — 4y
0
Also, you changed the title to how to disconnect the function? You can disconnect your event-triggered function by making it a variable and using :Disconnect() SaltyPotter 362 — 4y
0
check my new answer, i have my new script there that will work if i know how to connect and disconnect the function when i click the buttons Gameplayer365247v2 1055 — 4y

Answer this question