"Unable to cast string to int64"

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

2 Likes

What type of values are they? The player and place values

1 Like

The values mentioned in ReplicatedStorage are StringValues

1 Like

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.

1 Like

Ohh, so how do I transfer the instance to the script?

1 Like

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)

2 Likes

You define the location here:

And then you use your variable here:

You already have it defined to Replicated Storage so you dont need to define its location again… just do placeID.Value.

As for the error i believe you are assigning a value to a string, which requires a toNumber i believe.

1 Like

I agree with this and i believe he can also convert the string to an integer by using toNumber().

1 Like

This is used after the teleportation

1 Like

This is already a NumberValue, and it didn’t work. ObjectValues also don’t work as they say Argument 1 nil for me

1 Like

Can you show me which line the “Unable to cast string to int64” error is occurring on?

1 Like

image
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

2 Likes

But it was originally a string, I suppose

1 Like

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.

1 Like

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

1 Like

Converting Strings

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 .

1 Like
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
4 Likes

try using tonumber() on the placeID.Value thing,