18:13:51.541 Infinite yield possible on 'ReplicatedStorage.Events:WaitForChild("GetData")' - Studio
18:13:51.541 Stack Begin - Studio
18:13:51.541 Script 'ServerScriptService.Datastore', Line 9 - Studio - Datastore:9
18:13:51.541 Stack End - Studio
My Script Looks like This:
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local database = DataStoreService:GetDataStore("database")
local functions = ReplicatedStorage:WaitForChild("Events")
local events = ReplicatedStorage:WaitForChild("Functions")
local getDataFunc = functions:WaitForChild("GetData")
local exitEvent = events:WaitForChild("ExitGame")
local MAX_SELECTED_TOWERS = 5
local data = {}
local function LoadData(player)
local success = nil
local playerData = nil
local attempt = 1
repeat
success, playerData = pcall(function()
return database:GetAsync(player.UserId)
end)
attempt += 1
if not success then
warn(playerData)
task.wait()
end
until success or attempt == 3
if success then
print("Connection Success")
if not playerData then
print("New Player, Giving Default Data")
playerData = {
["Credits"] = 175,
["SelectedTowers"] = {"Iron Man MK5"},
["OwnedTowers"] = {"Iron Man MK5", "Wolverine"}
}
end
data[player.UserId] = playerData
else
warn("Unable to get data for player", player.UserId)
player:Kick("There was a problem getting your data, We're Sorry!")
end
end
Players.PlayerAdded:Connect(LoadData)
local function SaveData(player)
if data[player.UserId] then
local success = nil
local playerData = nil
local attempt = 1
repeat
success, playerData = pcall(function()
return database:UpdateAsync(player.UserId, function()
return data[player.UserId]
end)
end)
attempt += 1
if not success then
warn(playerData)
task.wait()
end
until success or attempt == 3
if success then
print("Data Saved Successfully")
else
warn("Unable to get save data for", player.UserId)
end
else
warn("No Session Data For", player.UserId)
end
end
exitEvent.OnServerEvent:Connect(function(player)
SaveData(player)
data[player.UserId] = nil
end)
game:BindToClose(function()
if not RunService:IsStudio() then
for index, player in pairs(Players:GetPlayers()) do
task.spawn(function()
SaveData(player)
end)
end
else
print ("Shutting Down Inside Studio")
end
end)
getDataFunc.OnServerInvoke = function(player)
return data[player.UserId]
end
If Anyone Knows How to Fix This I will be so appreciative, thank you.
Im making a Tower Defense Game using "GnomeCodes" Tower Defense Tutorial Videos, Im on the last one and on the section "Getting Players Chosen Towers" so thats what im expecting to happen but whenever I play test it, The Towers are blank and no where to be seen.
local functions = ReplicatedStorage:WaitForChild("Events")