Hello , i have been creating a script builder , i made two places one for waiting and another to give the info that the servers will update... The problem i have is that when i try to give the request it doesn't work
Code of the request of updates
-- RemoteEvent will be called by a localscript game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr) print("Received request.") local data = game:GetService("DataStoreService") local startUpdate = data:GetDataStore("CENSORED") startUpdate:UpdateAsync("UPDTSRVS",function(old) local newValue = old newValue = newValue+1 return newValue end) end)
Code of the script that will action on update
local connection function MessageToScreen(msg,isperm,waitt) local a = Instance.new("Message") a.Name = "ys27h872hs3gd7agd726ds8agwd972gdsga78wgd27d3" a.Parent = workspace a.Text = msg if isperm == false then wait(waitt) a:remove() end end function UpdateServers(key) print("Starting..") MessageToScreen("Servers Are Updating , Please wait...",true,math.huge) print("Teleporting") for i,v in pairs(game:GetService("Players"):GetPlayers()) do game:GetService("TeleportService"):Teleport(838000617,v) end end connection = startUpdate:OnUpdate("UPDTSRVS",UpdateServers)
I found out that this works , but when i join the game the connection runs , and i did not even change any value in DataStore.. Please help
Well, my best assumption would be that in the first block of code in the update function you automatically index 'old' without checking if it is nil. So rather than just having:
local newValue = old
You would add a new argument to it when declaring it as 'newValue'
local newValue = old or 0
What it is basically doing is that if the value is nil it turns over to a different object/value which is 0. I don't really understand the issue completely but this is the best shot I can give at the moment.