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

Text-based walkspeed script not working?

-- NOTE: I'm awful new to Lua. --

I've created a script so that whenever a whitelisted player inputs someone's name into a specific textbox and a number into another specific text box, the inputted player's WalkSpeed will change into the said number. This is in a LocalScript. Here's my current code:

local ign = game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame.Panel.PlayerBox.Text

while true do
	game.Players:FindFirstChild(ign).Character.Humanoid.WalkSpeed = script.Parent.Text
	wait(1)
end

I've made sure that all of the directories are correct (parents/children). Any help is appreciated!

~ atatakaiz

3 answers

✓ Accepted answer

(Warning: This answer is too long. The answer is in the down, so if you lazy to read, just scroll to the downest!)

Hi there! It seems you like new to LUA, so I'll say it simple, and easy to learn, follow this step-by-step! Honestly, I was bad at English, so sorry for the grammars! :P

Before I start, I'll explain those 2 people's answers.

local a = '1'
print(type(a))--> string
a = tonumber(a);
print(type(a))--> number

local b = 'wow string!'
b = tonumber(b)
print(b) --> nil

Let make this become 2 parts, the up part, and the down part.

The up part:

local a = '1'
print(type(a))--> string
a = tonumber(a);
print(type(a))--> number

We're local the 'a' become 1. But the 'a' is a number, so change it to number. If we use string, it still works.

The down part:

local b = 'wow string!'
b = tonumber(b)
print(b) --> nil

The 'b' is not a number, so if you make it to number, it will become nil, definitely printed nothing out.

So we can know tonumber() is a thing that changes string to number!

Yeah, it's was already self-explanatory. Right?

Another one:

while true do wait()
    local player = game.Players:FindFirstChild(script.Parent.Text)
    if player ~= nil then
        player.Character.Humanoid.WalkSpeed = script.Parent.Parent.Speed.Text -- Speed is the other textbox where the player will input the new WalkSpeed of the player humanoid
    end
end

I don't support to use this script, because the while true do, it always updates the script in 0.000317 seconds. So it might cause lag, and another, player.Character.Humanoid.Walkspeed. Sorry, a Humanoid is not in the workspace, it appears if you run the game, so we must use WaitForChild(), wait for the child out. Yeah, it's funny if you read it.

If you mentioned why tonumber() and the WaitForChild() have a bracket, it just an ObjectValue. ObjectValue is a value which cast the object, it was not like the string, it was defined to an object.

So, I recommend to use this script:

Also, credit to AntoninFearless. I used his script.

while wait(.5) do -- update the script every 0.5 seconds.
    local player = game.Players:FindFirstChild(script.Parent.Text)
    if player ~= nil then
        player.Character:WaitForChild("Humanoid").WalkSpeed = script.Parent.Parent.Speed.Text -- Speed is the other textbox where the player will input the new WalkSpeed of the player humanoid
    end
end

Maybe this will work, I don't know, if it works, mark this as answer, and tell me below the comment, if it was incorrect, I'll try my best to find the problem, and fix it! If you have more questions, PM me in ROBLOX, and also cyaaaaaaaaa

3 comments

0

NOTE: Rip grammar teacher, I did 15 mistake Xd

0

Thanks for the help! Works perfectly.

0

Thanks!

The Property Text is a string while Humanoid.WalkSpeed is a number based property. Try using global tonumber. Note it returns nil if the string is not a number.

Example:

local a = '1'
print(type(a))--> string
a = tonumber(a);
print(type(a))--> number

local b = 'wow string!'
b = tonumber(b)
print(b) --> nil

1 comment

0

I don't quite understand (as I mentioned in the post, I'm really new to Lua so I understand very limited), but thanks for trying to help.

Hello, in order to process this function add a local script into the text box that the player name will be put and put the following:

while true do wait()
	local player = game.Players:FindFirstChild(script.Parent.Text)
	if player ~= nil then
		player.Character.Humanoid.WalkSpeed = script.Parent.Parent.Speed.Text -- Speed is the other textbox where the player will input the new WalkSpeed of the player humanoid
	end
end

1 comment

0

Thanks for helping! This seems to work, but occasionally the player's walkspeed skips back to 16 then back to the number inputted. Any follow-up?

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