I am developing a game, which needs certain values to teleport to another place. Although, whenever I run it it ends up with this error message.
Unable to cast string to int64
So if anybody can help me with this, and I’ll put the code down below PLEASE do so.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TeleportService = game:GetService("TeleportService")
while wait(0.5) do
if ReplicatedStorage.isFired == false then
else
local plrName = ReplicatedStorage.plrName
local placeID = ReplicatedStorage.placeID
TeleportService:TeleportAsync(placeID.Value,{plrName.Value})
wait(2)
ReplicatedStorage.isFired.Value = false
ReplicatedStorage.placeID.Value = ""
plrName.Value = ""
end
end
I see, the player argument in TeleportAsync must be referred to a player instance, meaning the players object itself. Not his name.
Other than that, I dont see any other issues here.
I’m not a very good scripter but have you tried an numbervalue for the placeid value object instead?
Saying this since roblox is complaining about you trying to assign a string value to something thats supposed to be a 64-bit integer (e.g the place id)
This is because I’ve noticed that you made the numbervalue equal to a string. Strings inside scripts are notated by " ", while you don’t need to specifically notate numerals. Maybe try making it equal something like 0 instead? Because the placeid 0 doesn’t really exist and you could use that as a default value
The DevHub page for the PlaceId property states that it should be a 64-bit integer, so you have to convert the string to a number by using a toNumber function or just simply making it equal zero or nil.
Is the error really coming from this script? Could you send what line it’s erroring in? (should be included in the error message in the output)
I’m not able to replicate this issue at all even after trying to:
Set a number value’s value to “” (converts it to 0)
Put a string inside of placeID (TeleportAsync already does a tonumber() with the placeID argument)
The only error I’m getting is from casting a string to Object, which comes from the TeleportAsync receiving a string table (the player’s name) instead of a table with the player instance
You can easily convert a string to a number by using the tonumber() function. This function takes one argument (the string) and returns it as a number. If the string doesn’t resemble a number, for example "Hello" , the tonumber() function will return nil .
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TeleportService = game:GetService("TeleportService")
while wait(0.5) do
if ReplicatedStorage.isFired == false then
else
local plrName = ReplicatedStorage.plrName
local placeID = ReplicatedStorage.placeID
local plr = Players:FindFirstChild(plrName.Value)
TeleportService:TeleportAsync(tonumber(placeID.Value),{plr})
wait(2)
ReplicatedStorage.isFired.Value = false
ReplicatedStorage.placeID.Value = ""
plrName.Value = ""
end
end