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

Unable to cast value to Object?

Asked by 5 years ago

Okay. I've been experimenting with Roblox code for a while now. But I still have a lot to learn, such as this problem.

I was creating this island game called "Island Accident", when while trying to teleport, it failed. I've been experimenting on the in-game part (not studio) and it still didn't work. I have a script which detects if the players have played the game before, which then calls a RemoteEvent named "Teleport" in ReplicatedStorage, which then goes to the Client, which tries to teleport the LocalPlayer, but fails with the message "Unable to cast value to Object".

DetectScript (server-sided script in ServerScriptService)

game.Players.PlayerAdded:connect(function(plr)
wait()
local DataStoreService = game:GetService("DataStoreService")
local TeleportService = game:GetService("TeleportService")
local DataStore = DataStoreService:GetDataStore("Stats")
local TeleportEvent = game:GetService("ReplicatedStorage"):WaitForChild("Teleport")
local success1, error1 = pcall(function()
local FinishedBeginning = DataStore:GetAsync("FinishedBeginning_"..plr.Name)
if FinishedBeginning == false then
TeleportEvent:FireClient(2970946504)
elseif FinishedBeginning == true then
TeleportEvent:FireClient(2971209365)
end
end)
if success1 == true then
print("Success!")
else
warn(error1)
end
end)

TeleportScript (client-sided script in StarterGui)

local TeleportEvent = game:GetService("ReplicatedStorage"):WaitForChild("Teleport")
local TeleportService = game:GetService("TeleportService")
local player = game.Players.LocalPlayer
TeleportEvent.OnClientEvent:connect(function(id)
wait()
TeleportService:Teleport(player,id,{},game:GetService("ReplicatedStorage").LoadingScreen)
end)

Please help someone, it would be awesome for me!

0
Nothing after 30 minutes? CrastificeDude612 71 — 5y
0
At first glance I think FireClient still needs the player argument try "TeleportEvent:FireClient(plr, 1234567)" ABK2017 406 — 5y

Answer this question