Hi guys! I need help with something again, I’m trying to make some sort of mind-game and I need the game to show the players name with the string “Your name is _____.”. I’ve tried this multiple times and it didn’t work.
for i = 1, #"Your name is "..game.Players.LocalPlayer.Name do
script.Parent.Frame.Label.Text = string.sub("Your name is "..game.Players.LocalPlayer.Name, 1, i)
wait(0.05)
end
The error I get:
Players.DokuDako.PlayerGui.ScreenGui.LocalScript:47: 'for' step must be a number
I’m assuming it’s just the order of operations here messing up. Try putting brackets around it and see if that fixes the problem:
for i = 1, #("Your name is "..game.Players.LocalPlayer.Name) do
script.Parent.Frame.Label.Text = string.sub("Your name is "..game.Players.LocalPlayer.Name, 1, i)
wait(0.05)
end
And if not, you could probably fix it by setting a variable to that & then doing #variable
You should store your string in a variable so that it becomes easier to work with, rather than writing out the text you need twice over. I feel like this is part of the reason why you got tripped up.
local textToWrite = "Your name is "..game:GetService("Players").LocalPlayer.Name
for i = 1, #textToWrite do
-- Alternate method so you only have to pass numbers is to call sub on
-- the string itself. This is equivalent to string.sub(string, i, j).
script.Parent.Frame.Label.Text = textToWrite:sub(1, i)
end