WalkSpeed not changing

doing an inputbegan event, but my walkspeed doesnt change when the condition is met. I have to hold down the key for my walkspeed to be changed despite there not being a condition for the key to be held down.

function LightFire(input)
	if input.KeyCode ~= Enum.KeyCode.E or not gui  then return else
		local lit = gui.Adornee:FindFirstChild("Activated")
		if lit.Value == true then
			bonfiregui.Enabled = true
			humanoid.WalkSpeed = 0
			bonfiregui.ExitButton.MouseButton1Down:Connect(function()
				bonfiregui.Enabled = false
				humanoid.WalkSpeed = 16
			end)
		end

The issue could probably get fixed by this:

local mouseDownConnection: RBXScriptConnection = nil
mouseDownConnection = bonfiregui.ExitButton.MouseButton1Down:Connect(function()
	mouseDownConnection:Disconnect()

	bonfiregui.Enabled = false
	humanoid.WalkSpeed = 16
end)

I tried using it but it still only modified my walkspeed to 0 when I held down the E key.

If this is a LocalScript (which it may be, since it handles the GUI) You will need to find a way to do this server-side. You cannot change server variables like WalkSpeed Client-Side

2 Likes

Local Script

function LightFire(input)
	if input.KeyCode ~= Enum.KeyCode.E or not gui  then return else
			local lit = gui.Adornee:FindFirstChild("Activated")
		if lit.Value == true and gui.Enabled == true then
			bonfiregui.Enabled = true
			gui.Enabled = false
			remoteevent:FireServer(humanoid)
		bonfiregui.ExitButton.MouseButton1Down:Connect(function()
				bonfiregui.Enabled = false
				gui.Enabled = true
				remoteevent:FireServer(humanoid)
			end)
		end

Server Script

game.ReplicatedStorage.Run2.OnServerEvent:connect(function(p, humanoid)
	if humanoid.WalkSpeed == 16 then
		humanoid.WalkSpeed = 0
	elseif humanoid.WalkSpeed == 0 then
		humanoid.WalkSpeed = 16
	end
end)

Same thing still ends up happening, my walkspeed will only be modified if I hold down the key.

Hello. It would be much easier to help with your issue if you sent the entire script. That way I can break it down and see what’s really going on here.

1 Like

Mind sending the “humanoid” variable?

1 Like

Im an idiot. I just realized that in my InputEnded function, it would reset my walkspeed back to 16 if I let go of E.

1 Like