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

Why does it run with InputEnded and not InputBegan ?

Asked by 8 years ago

It starts charging the bar when you stop holding the Q key. Not when it's being held. Why ?

Server Sided >



local rep = game:GetService("ReplicatedStorage") local remfunc = Instance.new("RemoteFunction", rep) remfunc.Name = "NenFunction" function remfunc.OnServerInvoke(Player, Request) if Request == "Began" then local char = Player.Character local humroot = char.HumanoidRootPart local plrgui = Player.PlayerGui local general = plrgui.GeneralScreen local nenstatus = general.NenStatus local expstatus = general.ExpStatus local MaxNen = nenstatus.MaxNen local Nen = nenstatus.Nen local nenlabel = nenstatus.NenBar for i = 1, MaxNen.Value do wait() nenlabel.Size = UDim2.new((Nen.Value+i/MaxNen.Value), 0, 1, 0) end else if Request == "Ended" then local char = Player.Character local plrgui = Player.PlayerGui local general = plrgui.GeneralScreen local nenstatus = general.NenStatus local expstatus = general.ExpStatus local MaxNen = nenstatus.MaxNen local Nen = nenstatus.Nen local nenlabel = nenstatus.NenBar nenlabel.Size = UDim2.new((Nen.Value/MaxNen.Value),0,1,0) end end end

Client

local player = game.Players.LocalPlayer

repeat wait() until player.Character

local char = player.Character
local hum = char:WaitForChild("Humanoid")
local humroot  = char:WaitForChild("HumanoidRootPart")

local UIS = game:GetService("UserInputService")
local IB = UIS.InputBegan
local IE = UIS.InputEnded


-- // Remote Function


local rep = game:GetService("ReplicatedStorage")
local remfunc = rep:WaitForChild("Ten")
local remfunc2 = rep:WaitForChild("NenFunction")

-- // Remote Function

local deb = true
local playing = false

IB:connect(function(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.Q then
      if deb then
         deb = false
         playing = true
         remfunc:InvokeServer("Began")
         remfunc2:InvokeServer("Began")
         repeat wait() until not playing
         deb = true
      end
   end
end)


IE:connect(function(inputObject, gameProcessedEvent)
   if inputObject.KeyCode == Enum.KeyCode.Q then
      wait()
      playing = false
      remfunc:InvokeServer("Ended")
      remfunc2:InvokeServer("Ended")
   end
end)

Answer this question