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

why doesnt this keycode work?

d = false

function onKeyPress(inputObject, gameProcessedEvent)
 if d == true then 
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16
   elseif inputObject.KeyCode == Enum.KeyCode.R then
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 100
d = true
    end
end

game:GetService("UserInputService").InputBegan:connect(onKeyPress)

it makes me faster and slower once, it works perfectly once. i thought about putting a loop in, but i dont want a wait time. any ideas?

3 comments

0

Is it a LocalScript in PlayerGui, PlayerScripts, Backpack, or the Player's Character? UserInputService is a Client-Sided service.

0

tank you, i as using a server script inside the workspace

0

updated the question, because new problem.

1 answer

✓ Accepted answer
function onKeyPress(inputObject, gameProcessedEvent)
	if gameProcessedEvent then return end
	
	if inputObject.KeyCode == Enum.KeyCode.D then
 		if game.Players.LocalPlayer.Character.Humanoid.WalkSpeed == 16 then 
			game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 100
		else
			game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16
    	end
	end
end

game:GetService("UserInputService").InputBegan:connect(onKeyPress)

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