Unable to cast value to object error

Hello , im trying to make a player get teleported to another game but im getting this error unable to cast value to object
this is the script parented to a proximty prompt

local ProximityPrompt = script.Parent
local TeleportService = game:GetService("TeleportService")
local placeId = tonumber(script.Parent.Parent.Gameid.Value)
local gamename = script.Parent.Parent.SurfaceGui.GameName.Text

ProximityPrompt.ActionText = gamename

local function onProximityPromptTrigger(player)
	print(player,placeId)
	TeleportService:Teleport(player,placeId)
	print("Teleportation successful!")
end

ProximityPrompt.Triggered:Connect(onProximityPromptTrigger)

2 Likes

placeId is the first parameter and player is the second

2 Likes

Thanks , but now im getting teleported to random games for some odd reason

1 Like

You have viruses in your game probably. Put c:Script into the explorer search bar then look for scripts you didn’t make. Repeat the same process with c:LocalScript

But in honesty, since your problem is solved it would probably be best to mark @yoshicoolTV’s answer as the solution and open up a new topic.

Well i used some like 4 or 6 free models but none of them had scripts , so the chances of it being a virus is low

If you want to teleport players to a specific place, then why not store the place’s ID in a constant variable like so:

local TeleportService = game:GetService("TeleportService")

local PLACE_ID = 123456 -- Replace this with the actual place ID

local proximityPrompt = script.Parent

proximityPrompt.Triggered:Connect(function(player)
	TeleportService:Teleport(PLACE_ID, player)
end)

Still good to check though. I’m struggling to think of another reason why you’d be teleported to other games. If you decide to open up a new topic I’ll tell you the best way to check for game teleports.

Try running this script in the studio console and see the result.

for _, e in game:GetDescendants() do
	if e:IsA("LuaSourceContainer") and (e.Source:lower() :: string):match("teleport%s?service") and (e.Source :: string):lower():match("teleport[%p%a]*") then
		print(e:GetFullName() .. " contains teleport")
	end
end

image

Turn off all your suspicious plugins, they may also be causing the problem.

well only the part with proximityprompt contains the script with the teleport , also turned off all my plugins even tho they werent much suspicious , still the same problem

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.