So, I’ve made a ScreenGui where if you click on a ImageButton, a StringValue will be changed with the numbers given. Those numbers are meant to be a PlaceID, which are used in a TextButton to teleport the player.
I keep getting Argument 1 missing or nil on the Output on line 4, which won’t teleport me to the game.
I’ve tried to changing the Scripts to LocalScripts, but that doesn’t seem to be working. I also tried with NumberValue but I got "Cannot teleport to invalid place id. Aborting teleport. " which wouldn’t get me anywhere. I looked in the Forum, I found that “(tonumber())” should be used, yet I can’t find a solution.
The code for the TextButton is:
local PLACE = script.Parent.Value.Value
script.Parent.MouseButton1Click:Connect(function(Player)
script.Parent.Text = "TELEPORT"
game:GetService('TeleportService'):Teleport(tonumber(PLACE), game.Players.LocalPlayer)
end)
I think that the mistake might be when you transform your string into a number.
try replacing “PLACE” with":
local PLACE = script.Parent.Value
and in line 4:
game:GetService(‘TeleportService’):Teleport(PLACE.Value, game.Players.LocalPlayer)
^Considering “PLACE” is a Number Value, i dont see why you would use string values here
Roblox will automatically cast the type to number if possible so you can safely remove that tonumber(PLACE) but try printing the value of PLACE to make sure its actually a placeId
I got to a point where it printed the ID, but I’m planning on being able to teleport to different places and the NumberValue did not update, remaining as 0.
Yes. I’ve tried everything that comes to my mind. Do you have any suggestions for me to test? The ID has to constantly change every time an ImageButton gets pressed, yet I keep getting errors on the output. I just don’t want to make an individual script for each one of the teleporters.
So it would be something like this. Each label is a map, with a corresponding ID. Once you’ve picked a map, you can either pick another map (update the place ID), or press the Teleport button to go to said place. I’m thinking I could maybe do it as an if statement, roughly, something like “if text = map1 then teleport to place map1”.