Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why Does Is This Kick Script So Glitchy?

The sounds are out of sync, I think I coded the debounce incorrectly, and I kick two times even though I press "f" once. I tried everything.

plr = game.Players.LocalPlayer
uis = game:GetService("UserInputService")
debounce = true

repeat wait() until plr
local function ReceiveInput(Input)
	local IT = Input.UserInputType
	if IT == Enum.UserInputType.Keyboard then
		if Input.KeyCode == Enum.KeyCode.F and debounce then
			debounce = false
			animation = Instance.new("Animation")
			animation.AnimationId = "http://www.roblox.com/Asset?ID=357501529"
			AnimTrack = plr.Character.Humanoid:LoadAnimation(animation)
			AnimTrack:Play()
			sound = Instance.new("Sound")
			sound.SoundId = "rbxassetid://146163534"
			sound.Parent = plr.Character:FindFirstChild("Right Leg")
			sound.PlayOnRemove = true
			game.Debris:AddItem(sound,0)
		end
		wait(1)
		debounce = true
		AnimTrack:Stop()
		game.Debris:AddItem(animation,0)
	end
end

uis.InputBegan:connect(ReceiveInput)
uis.InputEnded:connect(ReceiveInput)
uis.InputChanged:connect(ReceiveInput)

1 answer

✓ Accepted answer
local plr = game.Players.LocalPlayer --Changed to local (because it looks nicer :p)
local uis = game:GetService("UserInputService")
local debounce = true

repeat wait() until plr.Character --Waiting for the character to load

local function ReceiveInput(Input)
    local IT = Input.UserInputType
    if (IT == Enum.UserInputType.Keyboard) then
        if (Input.KeyCode == Enum.KeyCode.F) and debounce then
            debounce = false
            local animation = Instance.new("Animation")
            animation.AnimationId = "http://www.roblox.com/Asset?ID=357501529"
            local AnimTrack = plr.Character.Humanoid:LoadAnimation(animation)
            AnimTrack:Play()
            local sound = Instance.new("Sound")
            sound.SoundId = "rbxassetid://146163534"
            sound.Parent = plr.Character:FindFirstChild("Torso")
            sound.PlayOnRemove = true
            game.Debris:AddItem(sound,0)
	    wait(1)
            debounce = true
            AnimTrack:Stop()
            animation:Destroy()
        end
    end
end

uis.InputBegan:connect(ReceiveInput)
uis.InputEnded:connect(ReceiveInput)
uis.InputChanged:connect(ReceiveInput)

I haven't changed much, so try this and tell me if it works or not, then edit in this code and I'll look into it a bit deeper.

This discussion is preserved as it was. New answers, comments, and votes are closed.