(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))
a = tonumber(a);
print(type(a))
local b = 'wow string!'
b = tonumber(b)
print(b)
Let make this become 2 parts, the up part, and the down part.
The up part:
local a = '1'
print(type(a))
a = tonumber(a);
print(type(a))
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)
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
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
local player = game.Players:FindFirstChild(script.Parent.Text)
if player ~= nil then
player.Character:WaitForChild("Humanoid").WalkSpeed = script.Parent.Parent.Speed.Text
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
NOTE: Rip grammar teacher, I did 15 mistake Xd
Thanks for the help! Works perfectly.
Thanks!