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

Character walk speed not changing, what's wrong with this script?

This code is inside of a local script which is inside of the stamina bar that should get smaller after "q" is pressed. Neither the character's walk speed nor the re-sizing of the stamina bar is working. Can someone help me figure this out? I'm not very good at scripting.

function onKeyDown(key)
	if key ~= nil then
	key = key:lower()
	if key == "q" then
		script.Parent.Parent.Parent.Parent.Parent.WalkSpeed = 25
		for i = 1, 0, -0.001 do
			script.Parent.Size = 0.999
			wait(0.000001)
		end		
	end
	end
end

function onSelected(mouse)
	mouse.KeyDown:connect(onKeyDown)
end

1 answer

✓ Accepted answer

#Since this a LocalScript its gonna much easy to make.. :) I would use TweenSize for the GUI as well..

wait() -- Script load

local Player = game:GetService("Players").LocalPlayer -- LocalPlayer ONLY works local.
local Mouse = Player:GetMouse() -- Get mouse / keyboard

local Frame = script.Parent -- GUI frame?

local Wanted_Key = "q"

function ChangeDownSpeed(key)
	key = string.lower(key)
	if tostring(key) ~= tostring(Wanted_Key) then return end
	local User_Character = workspace:FindFirstChild(Player.Name) -- User Character
	if User_Character then
		local Humanoid = User_Character:FindFirstChild("Humanoid")
		if Humanoid then
			Humanoid.WalkSpeed = 25
			Frame:TweenSize(UDim2.new(1,0,1,0),"Out","Linear",.4)
		end
	end
end

function ChangeUpSpeed()
	Frame:TweenSize(UDim2.new(1,0,0,0),"Out","Linear",.4)
end

Mouse.KeyDown:connect(function(key) 
	ChangeDownSpeed(key) 
end)

Mouse.KeyUp:connect(function(key)
	key = string.lower(key)
	if tostring(key) ~= tostring(Wanted_Key) then return end
	ChangeUpSpeed()
end)

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