What do you want to achieve? Keep it simple and clear!
so its not really me that needs help but since i have done some major things for my friends game i am asking for help about a error.
What is the issue? Include screenshots / videos if possible!
so the error is
attempt to perform arithmetic (add) on nil and number
The code is
local Buttons = game.Workspace.Buttons
for i,button in pairs(Buttons:GetChildren()) do
local ClickDetector = button.ClickDetector
ClickDetector.MouseClick:Connect(function(player)
button.BrickColor = BrickColor.new("Bright red")
wait(1)
button.BrickColor = BrickColor.new("Lime green")
local Character = player.Character
local number = string.sub(button.Name, 2)
print(number)
--This line below is the error on
local DestinationName = "Stage"..tostring((tonumber(number)+1)).."TP"
print(DestinationName)
local Destination = game.Workspace.Teleports:FindFirstChild(DestinationName)
print(Destination)
if Destination then
Character.HumanoidRootPart.CFrame = Destination.CFrame
end
end)
end
What’s the value of the variable number and what did it print? tonumber returns nil if the string argument supplied isn’t numerical.
(Also you don’t need tonumber or tostring for concatenation with numbers as strings and numbers are automatically converted to strings or numbers when doing most anything with each other)
"%d+" is a string pattern. It doesn’t tell string.match to look for the pattern itself in the string. Instead, it tells it to look for numbers in the string.
Edit: % tells that it’s a special pattern. There are different character classes. d spesifies that the character class which’s occurrences should be found is digits (numbers). + tells that it should return the whole sequence of characters belonging to the given character class if there are multiple of them without any other characters between them.