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

I am trying to make a ban script but it says string expected, got instance on line 22. ???

Asked by 2 years ago
Edited 2 years ago
local banDS = game:GetService("DataStoreService"):GetDataStore("Bans")
local mods = {}
local admins = {476564429}

game:GetService("Players").PlayerAdded:Connect(function(plr)
    local key = "-Banned" .. plr.UserId
    local success, val = pcall(function()
        return banDS:GetAsync(key)
    end)
    if(success) then
        if(val) then
            if(val[2] == true) then
                plr:Kick("\n You have been permanently banned. \n Reason: \n" .. val[1])
            end
        end
    else
        print("error" .. plr.UserId .. " " .. plr.Name)
        warn(val)
    end
end)
game:GetService("ReplicatedStorage").WarnRequest.OnServerEvent:Connect(function(plr, reason)
    local text = game.Players[plr].Character.Head.Overhead.Warnings.Text
    local wrnings = game.Players[plr].Character.Head.Overhead.Warnings
    local amt = game.Players[plr].Warnings
    amt.Value = amt.Value + 1
    text = "W" .. amt.Value .. " - " .. reason
    if amt.Value >= 3 then
        game.Players[plr]:Kick("You've reached the maximum number of warnings and have been kicked from the server.")
    end
end)
game:GetService("ReplicatedStorage").BanRequest.OnServerEvent:Connect(function(mod, plr, reason)
    if(table.find(mods, mod.UserId)) then
        if not plr.UserId == admins then
            local key = "-Banned" .. plr.UserId
            local success, err = pcall(function()
                banDS:SetAsync(key, {reason, true})
            end)
            plr:Kick("\n You have been permanently banned. \n Reason: \n" .. reason) 
        end

    end
end)

game:GetService("ReplicatedStorage").UnbanRequest.OnServerEvent:Connect(function(mod, plr, reason)
    if(table.find(mods, mod.UserId)) then
        local key = "-Banned" .. plr.UserId
        local success, err =pcall(function()
            banDS:SetAsync(key, {reason, false})
        end)
    end
end)

game:GetService("ReplicatedStorage").KickRequest.OnServerEvent:Connect(function(mod, plr, reason)
    if(table.find(mods, mod.UserId)) then
        if not plr.UserId == admins then
            plr:Kick("\n You are kicked from this server. \n Reason: \n " .. reason)
        end

    end
end)

Now, i got the attempt to concatenate string with Instance error on line 26. Script now:

local banDS = game:GetService("DataStoreService"):GetDataStore("Bans")
local mods = {}
local admins = {476564429}

game:GetService("Players").PlayerAdded:Connect(function(plr)
    local key = "-Banned" .. plr.UserId
    local success, val = pcall(function()
        return banDS:GetAsync(key)
    end)
    if(success) then
        if(val) then
            if(val[2] == true) then
                plr:Kick("\n You have been permanently banned. \n Reason: \n" .. val[1])
            end
        end
    else
        print("error" .. plr.UserId .. " " .. plr.Name)
        warn(val)
    end
end)
game:GetService("ReplicatedStorage").WarnRequest.OnServerEvent:Connect(function(plr, reason)
    local text = plr.Character.Head.Overhead.Warnings.Text
    local wrnings = plr.Character.Head.Overhead.Warnings
    local amt = plr.Warnings
    amt.Value = amt.Value + 1
    text = "Warning " .. amt.Value .. ": Reason:" .. reason
    if amt.Value >= 3 then
        plr:Kick("You've reached the maximum number of warnings and have been kicked from the server.")
    end
end)
game:GetService("ReplicatedStorage").BanRequest.OnServerEvent:Connect(function(mod, plr, reason)
    if(table.find(mods, mod.UserId)) then
        if not plr.UserId == admins then
            local key = "-Banned" .. plr.UserId
            local success, err = pcall(function()
                banDS:SetAsync(key, {reason, true})
            end)
            plr:Kick("\n You have been permanently banned. \n Reason: \n" .. reason) 
        end

    end
end)

game:GetService("ReplicatedStorage").UnbanRequest.OnServerEvent:Connect(function(mod, plr, reason)
    if(table.find(mods, mod.UserId)) then
        local key = "-Banned" .. plr.UserId
        local success, err =pcall(function()
            banDS:SetAsync(key, {reason, false})
        end)
    end
end)

game:GetService("ReplicatedStorage").KickRequest.OnServerEvent:Connect(function(mod, plr, reason)
    if(table.find(mods, mod.UserId)) then
        if not plr.UserId == admins then
            plr:Kick("\n You are kicked from this server. \n Reason: \n " .. reason)
        end

    end
end)
0
Because `game.Players[plr].Character.Head.Overhead.Warnings.Text` is not a string but rather a Textbox or something. If you highlight it you'll see the properties in the properties tab, for example if it's a textbox you need a `.Text` at the end. Miniller 562 — 2y

1 answer

Log in to vote
0
Answered by
enes223 327 Moderation Voter
2 years ago
Edited 2 years ago

OnServerEvent event gives you the player instance as the first argument, you don't need to do Players[plr] to get the instance, plr is already the player instance itself. You are trying to index Players with an instance and that's why you get the error. You can fix the line and others to:

local text = plr.Character.Head.Overhead.Warnings.Text
0
alr thanks leonalfy87 2 — 1y
Ad

Answer this question