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

InputBegan and InputEnded buggy? Looking for another method or fix

Asked by 7 years ago
Edited 7 years ago

new desc the ball just nonstop grows input ended doesnt even start ???

old desc I'm making a script that charges a beam when a button is pressed and held and then fired once the button is let go with filtering enabled and remote events. The script works but the InputBegan and InputEnded is super buggy and I now i need help with either fixing this or finding a new way to execute the script

sorry its kinda rushed

local script in startercharacterscripts (fires the event)

local uis = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local plr = game.Players.LocalPlayer
local char = plr.Character
local urFolder = ReplicatedStorage:WaitForChild(plr.Name)
local isKameCharging = urFolder:WaitForChild("IsKameCharging")
local kamehamehaEvent = ReplicatedStorage.Events:WaitForChild("KamehamehaEvent")
local SSJscript = script.Parent:WaitForChild("SSJ")
local isBeamFired = urFolder:WaitForChild("IsBeamFired")

local debounce = false
local cooldown = 6

local function kameFiring()
    if isKameCharging.Value == false and isBeamFired.Value == false then
    kamehamehaEvent:FireServer()
    end
end

uis.InputBegan:connect(function(input, inputProcessed)
    if debounce == false then debounce = true
    if inputProcessed == false and input.KeyCode == Enum.KeyCode.Z then
        print("hi")
        kameFiring()
        wait(cooldown)  
        return
    end
 debounce = false
    end
end)

script that receives the event (serverscriptservice)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local kamehamehaEvent = Instance.new("RemoteEvent", ReplicatedStorage.Events)
kamehamehaEvent.Name = "KamehamehaEvent"

local uis = game:GetService("UserInputService")

ready = true

local function onKameCharged(plr)
    print("mmm")
    local char = plr.Character
    local urFolder = ReplicatedStorage:WaitForChild(plr.Name)
    local isKameCharging = urFolder:WaitForChild("IsKameCharging")
    local SSJscript = char:WaitForChild("SSJ")
    local isBeamFired = urFolder:WaitForChild("IsBeamFired")
    local humanoid = char:WaitForChild("Humanoid")
    if isKameCharging.Value == false and isBeamFired.Value == false and ready then
    isKameCharging.Value = true
    print("z pressed, kamehameha isnt charging nor firing")
    SSJscript.Disabled = true
    humanoid.WalkSpeed = 0
    humanoid.JumpPower = 0
    local anim = Instance.new("Animation")
    anim.AnimationId = "http://roblox.com/asset/?id=1274860761"
    local animTrack = humanoid:LoadAnimation(anim)
    animTrack:Play()
    ready = false
    wait(.6)
    local chargePart = Instance.new("Part")
    chargePart.Parent = char
    chargePart.Anchored = true
    chargePart.CanCollide = false
    chargePart.Transparency = 0
    chargePart.formFactor = "Symmetric"
    chargePart.Size = Vector3.new(1.25, 1.25, 1.25)
    chargePart.TopSurface = "Smooth"
    chargePart.BottomSurface = "Smooth"
    chargePart.Name = "KamehamehaBall"
    chargePart.Shape = "Ball"
    chargePart.Material = "Neon"
    chargePart.CFrame = char.RightHand.CFrame + Vector3.new(-0.6,0,0)
    chargePart.BrickColor = BrickColor.new("Cyan")
    local outlineCharge = Instance.new("Part")
    outlineCharge.Parent = char
    outlineCharge.Anchored = true
    outlineCharge.CanCollide = false
    outlineCharge.Transparency = 0.9
    outlineCharge.formFactor = "Symmetric"
    outlineCharge.Size = Vector3.new(1.75, 1.75, 1.75)
    outlineCharge.TopSurface = "Smooth"
    outlineCharge.BottomSurface = "Smooth"
    outlineCharge.Name = "KamehamehaBallOutline"
    outlineCharge.Shape = "Ball"
    outlineCharge.Material = "Neon"
    outlineCharge.CFrame = chargePart.CFrame
    outlineCharge.BrickColor = BrickColor.new(248,248,248)
    script.plrName.Value = plr.Name
    script.Script.Disabled = false
    ready = true
    local debounce = false
    local cooldown = 5
    uis.InputEnded:connect(function(input, inputProcessed)
        if debounce then debounce = true 
        if inputProcessed == false and input.KeyCode == Enum.KeyCode.Z then
        isKameCharging.Value = false
        isBeamFired.Value = true
        animTrack:Stop()
        local fireanim = Instance.new("Animation")
        fireanim.AnimationId = "rbxassetid://1243133546"
        local fireTrack = humanoid:LoadAnimation(fireanim)
        fireTrack:Play()
        chargePart.Transparency = 1
        outlineCharge.Transparency = 1
        wait(.2)
        outlineCharge.Transparency = .9
        chargePart.Transparency = 0
        chargePart.CFrame = char.RightHand.CFrame + Vector3.new(0.6,0,.2)
--      outlineCharge.Parent = chargePart
        outlineCharge.CFrame = chargePart.CFrame
        wait(.2)
        chargePart:Destroy()
        outlineCharge:Destroy()
        humanoid.WalkSpeed = 16
        fireTrack:Stop()
        humanoid.JumpPower = 50
        local kame = char:WaitForChild("Kamehameha")
        kame.Disabled = false
        isBeamFired.Value = false
        wait(cooldown)      
        end
        debounce = false
        end
end)    
end
end
kamehamehaEvent.OnServerEvent:connect(onKameCharged)

1 answer

Log in to vote
0
Answered by 7 years ago

Your script is buggy, mainly because you forgot a few important essentials when creating a userinputservice function.

  1. You forgot to add a debounce, that may recharge.
  2. You forgot to check if the input was processed.

Here's an example of a correct, and not buggy userinputservice function;

local uis= game:GetService("UserInputService")
local debounce = false
local cooldown= 5

uis.InputBegan:Connect(function(input, inputProcessed)
    if debounce == false then debounce = true
        if inputProcessed == false and input.KeyCode == Enum.KeyCode.E then
            print("Cheese")
            wait(cooldown)
        end
    debounce = false
    end
end)
0
Updated the script, pretty sure i did it wrong can you look it over for me? Godlydeathdragon 227 — 7y
0
for some reason the script plays only one part of the script (the inputended part) is this because I did the debounce wrong? edit: now the ball only grows and it doesnt stop even though its supposed to stop at a certain time or when its disabled..  Godlydeathdragon 227 — 7y
Ad

Answer this question