Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

When i try to use a textbutton to tp the player it says the teleport id is invalid?

Asked by
danglt 185
5 years ago

here is the script that sets the id

local player = game.Players.LocalPlayer
local places = player.places
local id = script.Parent.Parent.TextBox.Text

function click()
    places.p11.Value = id
    script.Parent.Parent.Parent.Parent.Parent.MyGames.page1.game1.ImageLabel.Image = "http://www.roblox.com/Thumbs/Asset.ashx?format=png&width=420&height=230&assetId=" .. id
end
script.Parent.MouseButton1Click:Connect(click)

script that teleports you

local Players = game:GetService("Players")
local TeleportService = game:GetService("TeleportService")
local player = game.Players.LocalPlayer

local placeId = player.places.p11.Value

wait()

function click()
    TeleportService:Teleport(placeId, player)
end
script.Parent.MouseButton1Click:Connect(click)

2 answers

Log in to vote
3
Answered by
Rare_tendo 3000 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

Try using tonumber on the Id:

local Players = game:GetService("Players")
local TeleportService = game:GetService("TeleportService")
local player = game.Players.LocalPlayer

wait()

function click()
    TeleportService:Teleport(tonumber(player.places.p11.Value), player)
end
script.Parent.MouseButton1Click:Connect(click)
1
well thats not the reason, when i press the button that sets the id it doesent change the value of p11 danglt 185 — 5y
Ad
Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

You are running the code local placeId = player.places.p11.Value before the player updates this value. The variable placeId will be the same each time.

You need to get the new value

script.Parent.MouseButton1Click:Connect(function()
    TeleportService:Teleport(player.places.p11.Value, player) 
end)

Hope this helps.

0
or i could put the var. inside the function danglt 185 — 5y

Answer this question