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

I need help extremely quickly on how to fix this running script, can someone help?

Okay so I am making a game like Hello Neighbor. It's called Hello Friend! I made a gamepass that allows you to permanently without pressing shift. The only problem is that the gamepass isn't working correctly and there are already ALOT of people who bought it. I've been trying to fix this forever but I can't seem to fix it. Can someone please help?

Here is the script. It is ran as a localscript under starterplayer.startercharacterscripts:

local mouse = game.Players.LocalPlayer:GetMouse()
local running = false
character = script.Parent


mouse.KeyDown:connect(key) -- Run function
	key = string.lower(key)
	if string.byte(key) == 48 then
		running = true
		local keyConnection = mouse.KeyUp:connect(function (key)
			if string.byte(key) == 48 then
				running = false
			end
		end)
		
		character.Humanoid.WalkSpeed = 32
		repeat wait () until running == false
		keyConnection:disconnect()
		character.Humanoid.WalkSpeed = 20
		end

2 answers

✓ Accepted answer

It seems you are missing an end) right at the bottom of your code to close the KeyDown function.

Also, KeyDown is deprecated, and UserInputService is more effective anyway.

Here's some new code containing explanations of anything you don't know;

local uis = game:GetService("UserInputService")
local character = game.Players.LocalPlayer.Character --// Just in case the script gets moved
local human = character:WaitForChild("Humanoid")

local runKey = Enum.KeyCode.LeftShift
local movementSpeeds = { -- the bool is whether the player is running or not
	[true] = 32,
	[false] = 20
}

function setRun(bool) --// function for easily setting the speed
	human.WalkSpeed = movementSpeeds[bool] --// indexes the speed in the above table
end

uis.InputBegan:connect(function(key,gp) --// gp = Game processed event (it is true if the player is typing in a TextBox, for example)
	if gp == false and key.KeyCode == runKey then
		setRun(true) --// fires the function, making the player run
	end
end)

uis.InputEnded:connect(function(key,gp) --// key is an InputObject
	if gp == false and key.KeyCode == runKey then
		setRun(false) --// fires the function, making the player walk
	end
end)

Hope I helped!

~TDP

At what point in the script does it mention a gamepass?

1 comment

0

He has another script that does so. Anyways, his script works now

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