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

How to use the same key twice?

Asked by 4 years ago

Hello everyone, Its currently very late but I want to finish this before I go to sleep.

So I have a script where a player prints out "In" whenever they press H. However, with the else statement when I press H again it should print "Out". Could someone help me out with this because i'm missing something very simple or im just overthinking something. Thanks.

Local Script:

local REMOTES = game.ReplicatedStorage:WaitForChild("Events")

local uis = game:GetService("UserInputService");

----------------- Remote Function ----------------------

function UIS(key) -- Function for UserInputService
    if key.KeyCode == Enum.KeyCode.H then
        REMOTES.Printing:FireServer();
    end 
end 

uis.InputBegan:Connect(UIS); 

Server Script:

local REMOTES = game.ReplicatedStorage:WaitForChild("Events")

REMOTES.Printing.OnServerEvent:Connect(function(player)
local character = player.Character
    if character then 
        print("In")
    else
        print("Out")


    end
end)

1 answer

Log in to vote
0
Answered by 4 years ago
--Local script
local REMOTES = game.ReplicatedStorage:WaitForChild("Events")
local uis = game:GetService("UserInputService");
local bool = false

function UIS(key) -- Function for UserInputService
    if key.KeyCode == Enum.KeyCode.H then
     if bool ~= false then
        bool = not bool
        REMOTES.Printing:FireServer(true);
        else
        if bool ~= true then
        bool = not bool
        REMOTES.Printing:FireServer(false);
    end 
end 
end
end

uis.InputBegan:Connect(UIS); 

I edited both of them so the should work now

--Workspace script.
local REMOTES = game.ReplicatedStorage:WaitForChild("Events")

REMOTES.Printing.OnServerEvent:Connect(function(player,bool)
if bool == true then 
        print("In")
    elseif bool == false then
        print("Out")
    end
end)
0
Thank you! XxDashbotxX 4 — 4y
Ad

Answer this question