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

Im trying to do a updateServers script , and it does run but with an exception , why? (RE-ASK)

Asked by 5 years ago
Edited 5 years ago

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

0
Would be nice if there were any comments on there to indicate what is happening, what it's calling and what it's using. Basically telling what everything is supposed to do. lazycoolboy500 597 — 5y
0
ok , When i join a game i made , there's a gui , a localscript sends a message through a remoteEvent , the server script catches it and then it changes a value in a dataStore, while in the other game when it catches a new update in a key it runs the function UpdateServers() as callback, then in that function the script would make a message and would teleport everyone to a game , but the problem is maumaumaumaumaumau 98 — 5y
0
that the code is running everytime you join the game , and the key does not change , that's my problem maumaumaumaumaumau 98 — 5y
0
Messages are deprecated, and don't use global variables for functions. Always use local. User#19524 175 — 5y
0
but that won't help because that can be changed, global and local functions do not make sense , even if i use same name with a global or local function it still will be confused maumaumaumaumaumau 98 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

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.

0
I already had a value set maumaumaumaumaumau 98 — 5y
Ad

Answer this question