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

Ban GUI is not saving ban data. Can someone please help me?

Asked by 4 years ago

So, I made this ban GUI, and when I ban someone the ban doesn't save! Here are the scripts involved with this.

Local script in GUI.

script.Parent.MouseButton1Click:Connect(function()
    local Username = script.Parent.Parent.Username.TextBox.Text
    local Reason = script.Parent.Parent.Reason.TextBox.Text
    local Evidence = script.Parent.Parent.Evidence.TextBox.Text
    print("Button was pressed!")
        if game.Players:FindFirstChild(Username) then
            print("Succesfully got a player!")
            game.ReplicatedStorage.ModEvents.BanPlayer:FireServer(Username, Reason)
        else
            print("Player does not exist!")
    end
end)

Server script that gets the remote event.

game.ReplicatedStorage.ModEvents.BanPlayer.OnServerEvent:Connect(function(player, Username, Reason)
    game.Players:FindFirstChild(Username):Kick("\nYou have been banned for:\n"..Reason.."\n By: "..player.Name.. " | "..player.UserId)
    game.Players:FindFirstChild(Username).modstats.Banned.Value = true

    game.Players.PlayerAdded:Connect(function(player)
        if player.modstats.Banned.Value == true then
            player:Kick("\nYou are banned for:\n"..Reason.."\n By: "..player.Name.. " | "..player.UserId)
        end
    end)
end)

Datastore script.

local Players = game:GetService("Players"); 

local DataStoreService = game:GetService("DataStoreService");

local Datastore = DataStoreService:GetDataStore("BucksDataStore");


Players.PlayerAdded:Connect(function(player)
    local modstats = Instance.new("Folder", player)
    modstats.Name = "modstats"

    local Banned = Instance.new("BoolValue", modstats)
    Banned.Name = "Banned"
    Banned.Value = false

    local data = nil;

    local s, e = pcall(function()
        data = Datastore:GetAsync(player.UserId.."-cash")
    end)

    if(s) then
        print("Data successfully loaded.")
        data = data or false
        Banned.Value = data
    else
        warn("There was a problem loading data:", e);
    end
end);


Players.PlayerRemoving:Connect(function(player)
    local modstats = player.modstats
    local Banned = modstats.Banned

    local s, e = pcall(function()
        Datastore:SetAsync(player.UserId.."-cash", Banned.Value)
    end);

    if(s) then
        print("Data successfully saved.");
    else
        warn("There was a problem saving data:", e);
    end
end) 

If anyone could help, that would be greatly appreciated.

0
I dont really know how to script but there is a solution you can use I have this script ypu can use but you need to gtoto roblox studio nicemorew 26 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

I found a solution you can only use this in roblox

local banned = {ID,ID,ID} game.Players.PlayerAdded:connect(function(plr) for i,v in pairs(banned) do if plr.UserId == v then plr:Kick("Banned") end end end)

here it is Enjoy! :)

Ad

Answer this question