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

UpdateDatastore With no output?

Asked by 6 years ago

Dear readers, I'm making a cross-server serverlock, which I would like to control using a datastore and the updated event. My goal is that when a player says ";slock", that the Serverlock Database with Lock as key has been set to "True". I'm an experienced scripter, but I don't really see why I always get the message "Failed to lock servers". This is the script I currently have in ServerScriptService. It triggers when a player joins, then it triggers again when that player chats, and then it checks for his rank if the message is ;slock. To see if it worked, I use a pcall function. Useful to know: There is no output.

local DataStoreService = game:GetService("DataStoreService")
local LockStore = DataStoreService:GetDataStore("ServerLock")

game.Players.PlayerAdded:connect(function(player)
    player.Chatted:connect(function(msg)
        if player:GetRankInGroup(3809918) >= 14 then

            if msg == ";slock" then
                local success = pcall(function()
                    return LockStore:UpdateAsync("Lock", true)                  
                end)
                if success then
                    local msg = Instance.new("Hint")
                    msg.Text = "Servers locked"
                    msg.Parent = workspace
                else
                    local msg = Instance.new("Hint")
                    msg.Text = "Failed to lock servers"
                    msg.Parent = workspace
                end
            end
        end
    end)
end)

Thank you in advance, Jonas (marketmanager1 on roblox)

Answer this question