As the title says, the InputEnd is fired first. This only happens when I just do a simple click, nothing else. Any fixes?
Server:
local pressing = 0
local playersFireball
local maxSize = Vector3.new(5,5,5)
function KeyPress(player, state, mouse)
print('okay')
if state == "Began" then
KeyDown(player, mouse)
print('began')
wait()
else
KeyUp(player)
print('ended')
end
end
function KeyDown(player, mouse)
if pressing == 0 then
pressing = 1
local hrp = player.Character.HumanoidRootPart
hrp.Anchored = true
wait(0.5)
local fireball = Instance.new("Part")
fireball.Parent = workspace.Projectiles
fireball.Shape = "Ball"
--fireball.Size = Vector3.new(0.1, 0.1, 0.1)
fireball.CanCollide = false
fireball.Anchored = true
fireball.CFrame = hrp.CFrame*CFrame.new(0, 0, -5)
local damage = Instance.new("NumberValue");
damage.Name = "Damage"
damage.Value = 0
damage.Parent = fireball
local bv = Instance.new("BodyVelocity")
bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
bv.Velocity = mouse.lookVector * 250
bv.Parent = fireball
playersFireball = fireball
player.Character.Humanoid.WalkSpeed = 0
while pressing == 1 do
print(pressing)
fireball.Size = fireball.Size + Vector3.new(0.1,0.1,0.1)
damage.Value = damage.Value + 10
fireball.CFrame = hrp.CFrame*CFrame.new(0, 0, -5)
bv.Velocity = mouse.lookVector * 250
if fireball.Size.X >= maxSize.X then
KeyUp(player)
end
wait(0.1)
end
end
end
function KeyUp(player)
if pressing == 1 then
pressing = 0
print('up')
local fireball = playersFireball
fireball.Anchored = false
player.Character.HumanoidRootPart.Anchored = false
player.Character.Humanoid.WalkSpeed = 16
end
end
script.Parent.OnServerEvent:Connect(KeyPress)
Local:
local tool = script.Parent
local mouse = game.Players.LocalPlayer:GetMouse()
local debounce = true
local held = false
local UIS = game:GetService("UserInputService")
local equip = false
tool.Equipped:Connect(function(mouse)
equip = true
end)
UIS.InputEnded:Connect(function(Input, gameProcessedEvent)
if not gameProcessedEvent and equip == true then
local KeyCode = Input.UserInputType
if KeyCode == Enum.UserInputType.MouseButton1 then
script.Parent.Fireball:FireServer("Ended", mouse.Hit)
end
end
end)
UIS.InputBegan:Connect(function(Input, gameProcessedEvent)
if not gameProcessedEvent and equip == true then
local KeyCode = Input.UserInputType
if KeyCode== Enum.UserInputType.MouseButton1 and debounce == true then
debounce = false
script.Parent.Fireball:FireServer("Began", mouse.Hit)
wait(3) debounce = true
end
end
end)
tool.Unequipped:Connect(function()
equip = false
end)
Outputs:
okay(x2)
up
Players.Math_Solvers.Backpack.Fireball.Fireball.Script:59: attempt to index local 'fireball' (a nil value)
began