So, my admin script works nicely in studio but not in game. Here is my code:
--local script
--the player holder value's value is the player itself
Commands.BAN = function()
game.ReplicatedStorage.PermBan:FireServer(playerHolder.Value.Value, Reason.Text)
end
--script in Server script service
game.ReplicatedStorage.PermBan.OnServerEvent:Connect(function(moderator, target, reason)
target.Value.Value = true
local Datastores = game:GetService("DataStoreService")
local banData = Datastores:GetDataStore("BanData")
local success, errorMessage = pcall(function()
return banData:SetAsync(target, target.Value.Value)
end)
if success then
print(target.Name.. " Was succesfully added into the ban datastore")
else
print(target.Name.." experienced an error while being added into the ban datasoter")
end
task.wait(0.1)
target:Kick("You have been permanentaly banned from the game. If you want to appeal, join server xyz. Bannig Moderator: "..moderator.Name)
game.Players.PlayerAdded:Connect(function(plr)
if plr.Value.Value == true then
plr:Kick("You were kicked looool")
end
end)
end)
Im pretty bad at roblox datastores because I generally use an external site so yeah thanks in advance
My whole setup is basically there is an objectValue named (playerHolder) in the Ban text button, whose value is the player, so I can ban or kick the player w/ the GUI
target is just the player on the server script, because im passing the player from the client in FireServer
bruh no, lets just leave the whole MAGICAL setup ive made and get into the main issue, However the script is made, it works in studio w/ 0 errors but does not work in game, so can I get some help on that?
Alright, I will try to explain the whole setup of the code.
--inf is the table in which all of the GUI's are saved.
for _, v in pairs(inf) do
if v:IsA("TextLabel") and v.Name == "DisplayName" then
v.Text = player.DisplayName
end
if v:IsA("TextLabel") and v.Name == "PlayerName" then
v.Text = player.Name
end
if v:IsA("TextButton") then
local playerHolder = Instance.new("ObjectValue")
playerHolder.Parent = v
playerHolder.Value = player
v.MouseButton1Click:Connect(function()
Title.Text = v.Text
Confrim.Text = v.Text
Confrim.Value.Value = v
end)
end
end
Thank you but I don’t need this information all I need to know is what I posted in my post
I will tell you the problems
Going by this statement alone there is already a vital error
SetAsync takes (key,value) if you pass an Instance as a key it will save as Instance[1234] the next time the player joins their Instance will be Instance[98776]
The key should always have the players UserId in it
There are more problems too
It’s not shown in your posted code where you set player.Value.Value = true
Even if you have another script that will do that your onPlayerAdded code will run before it
Firstly you can’t save a player Instance to a datastore, even if you could when a player joins it will create a new Instance
What you need to do is use the players id as key and data as value, then when the player joins you can retrieve that data by doing DataStore:GetAsync(player.UserId) with that data you can do whatever you want like kick the player or construct more Instances and parent them to the player if you want.