-
What do you want to achieve? I have 100 teleporters that players touch and they are sent to other games. I have one script that handles all this. I want this script to be stable and not to crash every few days.
-
What is the issue? The teleport script basically works. Players happily use the game as a hub to find and teleport into other games. However, every couple days the script just crashes. All teleports simply stop working. Players just wonder around trying to teleport until I see this happening then I manually reset all servers.
-
What solutions have you tried so far? I need do do something to stop the script from occasionally breaking. I suspect maybe I need to put a pcall somewhere strategic. Because this is a live game, and I can’t reproduce the error (it takes 1000’s of teleporting players to eventually break it), and I’m a new programmer, I’m afraid of throwing darts and tinkering too much. I am looking for advice on how to stabilize this script.
local DataStoreService = game:GetService("DataStoreService")
local playerData = DataStoreService:GetDataStore("PlayerData")
local dataStore = DataStoreService:GetOrderedDataStore("Teleports")
local MP = game:GetService('MarketplaceService')
local RS = game:GetService("ReplicatedStorage")
local TS = game:GetService("TeleportService")
local popular = game.Workspace.Stories.NowPlaying
local popularTitle = popular.Frame.Title.SurfaceGui.TextLabel
local popularImage = popular.Decal
local popularAuthor = popular.Frame.Author.SurfaceGui.TextLabel
local popularBannor = game.Workspace.Zones.Popular.UpdateBrick.SurfaceGui.TextLabel
local Stories = workspace.Stories:GetChildren()
local DB = false
for _, Story in pairs(Stories) do
if Story:IsA("BasePart") then
Story.Frame.Trigger.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and DB == false then
DB = true
local character = hit.Parent
local player = game.Players:GetPlayerFromCharacter(character)
local id = Story:GetAttribute("ID") -- Get ID
print(Story.Name, id .. " has been touched by " .. player.Name)
dataStore:IncrementAsync(player.UserId, 1)
--dataStore:SetAsync(player.UserId, 5) -- Total debug, resets to 5 if I tested alot.
print(player.savedata.LastStory.Value)
player.savedata.LastStory.Value = id
print(player.savedata.LastStory.Value .. " Oh yeah!")
local success, err = pcall(function()
local playerUserId = "Player_" .. player.UserId
playerData:SetAsync(playerUserId, player.savedata.LastStory.Value) --Saves player data
end)
local PlayParticle = RS.PlayParticle -- put play particle on Story
local clonedPlayParticle = PlayParticle:Clone()
clonedPlayParticle.Parent = Story
character:WaitForChild("Humanoid").Jump = true
wait()
character.HumanoidRootPart.Anchored = true
-----setupNowPlaying-----------------------------
local Details = MP:GetProductInfo(id)
local StoryName = Details.Name
print(StoryName)
popularTitle.Text = StoryName
local StoryCreator = Details.Creator.Name
print(StoryCreator)
popularAuthor.Text = StoryCreator
local iconID = Details.IconImageAssetId --get the image
if iconID ~= 0 then -- check if there truly is an image
popularImage.Texture = "rbxthumb://type=Asset&id="..iconID.."&w=150&h=150" --set the image
end
popularBannor.Text = (player.Name .. " entered " .. StoryName)
popular:SetAttribute("ID", id)
------------------------------------------------------
TS:Teleport(id, player) --Start Telport
DB = false
end
end)
end
end