I am making a script where I call on InputBegan and to Fire a remote event. Whenever The InputBegan part of the code runs and I click on another button it starts the inputEnded part of the script then goes back to the InputBegan part. Are there any other ways I could this?
Here is the code
local function start(input, inputProccessed)
--if inputProccessed then
-- return
--end
if KeyDown() then
print("g")
Hold = true
CanCreate = true
HATrack:Play()
HATrack:AdjustSpeed(0)
game.ReplicatedStorage.FireFist:FireServer()
Torso.Anchored = true
local MoveMouseFunction
MoveMouseFunction = mouse.Move:Connect(function()
print(mouse.Hit)
Torso.CFrame = CFrame.new(Torso.Position, Vector3.new(mouse.Hit.p.X, mouse.Hit.p.Y,
mouse.Hit.p.Z))
if not KeyDown()then
MoveMouseFunction:Disconnect()
end
end)
end
end
local function ended(input, inputProccessed)
if inputProccessed then
return
end
print()
Torso.Anchored = false
if input.KeyCode == Enum.KeyCode.G then
FATrack:Play()
FATrack:AdjustSpeed(0)
HATrack:Stop()
Hold = false
local BG = Instance.new("BodyGyro", Torso)
BG.D = 50
BG.MaxTorque = Vector3.new(math.huge,math.huge,math.huge)
BG.CFrame = CFrame.new(Torso.Position,mouse.Hit.p)
local BP = Instance.new("BodyPosition", Torso)
BP.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
BP.Position = Torso.Position
if mouse.Target ~= nil then
BP.Position = mouse.Hit.p
else if mouse.Target == nil then
game.ReplicatedStorage.DestroyBall:FireServer()
BG:Destroy()
BP:Destroy()
wait(3)
FATrack:Stop()
end
end
game.ReplicatedStorage.DestroyBM.OnClientEvent:Connect(function()
BG:Destroy()
BP:Destroy()
FATrack:Stop()
end)
end
end
UIS.InputBegan:Connect(start)
UIS.InputEnded:Connect(ended)