So I have 3 scripts:
LocalScript chatcmds(in StarterPlayerScripts):
repeat
wait()
until _G.admins
local player = game.Players.LocalPlayer
local DSService = _G.DSService
local GetSaved = _G.admins
function has_value(tab, val)
for index, value in ipairs (tab) do
if value == val then
return true
end
end
return false
end
for _,object in pairs(GetSaved) do
if has_value(_G.defaultadmins, player.UserId) then
player.Team = game.Teams.Owner
else
player.Team = game.Teams.Admin
end
end
player.Chatted:connect(function(msg)
GetSaved = DSService:GetAsync("admins")
if has_value(GetSaved, player.UserId) then --admin commands
if has_value(_G.defaultadmins, player.UserId) then --main owner commands
if msg == ":reseta" then
print("Admins RESET!")
DSService:SetAsync("admins", _G.defaultadmins)
_G.admins = DSService:GetAsync("admins")
end
if split(msg, "%s")[1] == ":adda" then
if split(msg, "%s")[2] then
print("Admin added!")
local tempt = GetSaved
if not has_value(tempt, split(msg, "%s")[2]) then
table.insert(tempt, split(msg, "%s")[2])
end
DSService:SetAsync("admins", tempt)
_G.admins = DSService:GetAsync("admins")
end
end
if split(msg, "%s")[1] == ":removea" then
if split(msg, "%s")[2] then
print("Admin removed!")
local tempt = GetSaved
if has_value(tempt, split(msg, "%s")[2]) then
removekey(tempt, split(msg, "%s")[2])
end
DSService:SetAsync("admins", tempt)
_G.admins = DSService:GetAsync("admins")
end
end
end
if msg == ":lista" then
print("Admins:")
for _,object in pairs(GetSaved) do
print(object)
end
end
if split(msg, "%s")[1] == ":givem" then
if split(msg, "%s")[2] and split(msg, "%s")[3] then
if tonumber(split(msg, "%s")[3]) then
if game.Players:FindFirstChild(split(msg, "%s")[2]) ~= nil then
local p2 = game.Players:FindFirstChild(split(msg, "%s")[2])
p2.leaderstats.Money.Value = p2.leaderstats.Money.Value + split(msg, "%s")[3]
end
end
end
end
if split(msg, "%s")[1] == ":takem" then
if split(msg, "%s")[2] and split(msg, "%s")[3] then
if game.Players:FindFirstChild(split(msg, "%s")[2]) ~= nil then
if tonumber(split(msg, "%s")[3]) then
local p2 = game.Players:FindFirstChild(split(msg, "%s")[2])
if p2.leaderstats.Money.Value >= tonumber(split(msg, "%s")[3]) then
p2.leaderstats.Money.Value = p2.leaderstats.Money.Value - split(msg, "%s")[3]
end
end
end
end
end
end
end)
function removekey(tab, key)
for _,object in pairs(tab) do
if object == key then
table.remove(tab,_)
break
end
end
return tab
end
function split(pString, pPattern)
local Table = {} -- NOTE: use {n = 0} in Lua-5.0
local fpat = "(.-)" .. pPattern
local last_end = 1
local s, e, cap = pString:find(fpat, 1)
while s do
if s ~= 1 or cap ~= "" then
table.insert(Table,cap)
end
last_end = e+1
s, e, cap = pString:find(fpat, last_end)
end
if last_end <= #pString then
cap = pString:sub(last_end)
table.insert(Table, cap)
end
return Table
end
ServerScript Admins:
local DSService = game:GetService('DataStoreService'):GetDataStore('mydatastorehere')
_G.DSService = DSService
_G.defaultadmins = {98016926}
local GetSaved = DSService:GetAsync("admins")
if not GetSaved then
DSService:SetAsync("admins", _G.defaultadmins)
end
_G.admins = GetSaved
and server script gamepasses:
game.Players.PlayerAdded:connect(function(p)
p.CharacterAdded:connect(function(character)
repeat
wait()
until _G.admins
if game:GetService("GamePassService"):PlayerHasPass(p, 492262492) then --speed
workspace[p.Name]:WaitForChild("Humanoid").WalkSpeed = 100
end
if game:GetService("GamePassService"):PlayerHasPass(p, 496545632) then --vip
game.ReplicatedStorage.Spatula:Clone().Parent = p.Backpack
end
if has_value(_G.admins, p.UserId) then
game.ReplicatedStorage.Spatula:Clone().Parent = p.Backpack
workspace[p.Name]:WaitForChild("Humanoid").WalkSpeed = 100
end
end)
end)
function has_value(tab, val)
for index, value in ipairs (tab) do
if value == val then
return true
end
end
return false
end
The gamepasses script works, and gives me 2 spatulas(one from the gamepass, one from being owner), but the ChatCmds one doesn't work at all once published. I am being left on the neutral team. Note that mydatastorehere is not really my data store, I just wanted to make sure no one who reads this messes with the one I have. Can someone please tell me why I am not being put as owner(I am in testing mode)?
Doing a RemoteEvent like SwardGames said, I added this in the admin script:
local geta = Instance.new("RemoteEvent") -- creates the event object
geta.Parent = game.Workspace -- puts the event into the Workspace
geta.Name = "GetAsync" -- giving a name to the event so we can fire it specifically elsewhere
geta.OnServerEvent:connect(function(wtg) -- define the function that will be called when the event is fired
return DSService:GetAsync(wtg)
end)
However neither ChatCmds or Gamepasses can get past:
repeat
wait()
until workspace.GetAsync:FireServer("admins")
It just waits forever.

9 comments
Ahh yes! So how can I get the DataStoreService in my localscript? I forget why putting that line of code in didn't work, but I think it was because its a localscript.
You can't (if you could players could add/delete/change anything at will). You could use a RemoteFunction/RemoteEvent to contact the server and have the server save.
An ObjectValue should be able to hold the DataStoreService though, right?
No, because it wont replicate. It would be extremely bad design to allow a client to have the ability so save and write persistant data to the server.
Ok, do you mind giving me an example of how to do it? Because I never could get Remote Functions to work.
http://wiki.roblox.com/index.php?title=RemoteFunction_and_RemoteEvent_Tutorial
In the remote event, they have 2 arguments, player and arguments. But when the function is called, its only called with the arguments?
Please read the edit I made to the main post when you get a chance.
Use a RemoteFunction, as RemoteEvents cannot return anything. Also, the first argument of OnServerInvoke is the player who called it, IE: myRemoteFunction.OnServerInvoke = function(player, text) print("Player " .. player.Name .. " called my RemoteFunction to tell it " .. text) end