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

Why doesnt my character run when i press W twice?

local Player = game.Players.LocalPlayer
local Character = Player.Character
local Human = game.Players.LocalPlayer.Character
local Humanoid = Character.Humanoid
local TrcanjeAnim = Instance.new("Animation")
local Tapped = false
local Time = 0.75
 TrcanjeAnim.AnimationId = 'rbxassetid://04779444465'
 playTrcanjeAnim = Humanoid:LoadAnimation(TrcanjeAnim)

game:GetService("UserInputService").InputBegan:connect(function(input, gameprocesed)
	if input.KeyCode == Enum.KeyCode.W then
		if not Tapped then 
			Tapped = true 
			wait() 
			Tapped = false
		for i = 1,16 do playTrcanjeAnim:Play()
			Human:WaitForChild("Humanoid").WalkSpeed = 30
		end
	end
  end
end)

game:GetService("UserInputService").InputEnded:connect(function(input, gameprocesed)
	if input.KeyCode == Enum.KeyCode.W then
		for i = 1,16 do playTrcanjeAnim:Stop()
			Human:WaitForChild("Humanoid").WalkSpeed = 16
		end
	end
end)

Also tell me if i messed up something in my script this is my Discord ne#6297

3 comments

0

Are you using this in an localscript? It is not NotReplicated across the client and server so that will be needed.

0

Because Minecraft

0

You could use firstTick = tick() when they first press W, and lastTick = tick() when they press W again, and check if the time between those 2 are minimum. by doing lastTick - firstTick. Tick() is in seconds.

1 answer

First possible issue, are you using this in a localscript? This is important as UserInputService is NotReplicated, It should also be under StarterCharacterScripts in StarterPlayer. Second issue, you forgot a else after line 16. Third issue, the wait makes double pressing impossible, make it around 1 second.

Heres the fixed script:

local Player = game.Players.LocalPlayer
local Character = Player.Character
local Human = game.Players.LocalPlayer.Character
local Humanoid = Character.Humanoid
local TrcanjeAnim = Instance.new("Animation")
local Tapped = false
local Time = 0.75
 TrcanjeAnim.AnimationId = 'rbxassetid://04779444465'
 playTrcanjeAnim = Humanoid:LoadAnimation(TrcanjeAnim)

game:GetService("UserInputService").InputBegan:connect(function(input, gameprocesed)
    if input.KeyCode == Enum.KeyCode.W then
        if not Tapped then 
            Tapped = true 
            wait(1) 
            Tapped = false
	    else
            for i = 1,16 do playTrcanjeAnim:Play()
            	Human:WaitForChild("Humanoid").WalkSpeed = 30
            end
        end
    end
end)

game:GetService("UserInputService").InputEnded:connect(function(input, gameprocesed)
    if input.KeyCode == Enum.KeyCode.W then
        for i = 1,16 do playTrcanjeAnim:Stop()
            Human:WaitForChild("Humanoid").WalkSpeed = 16
        end
    end
end)

Please note this needs to be under StarterCharacterScripts in StarterPlayer.

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