Attempt to concatenate Instance with string

So um basically while i was making a warn system, and finished it, i came across a error. look to the title

local ws = require(script.Parent.WebhookService)
local url = "no am not giving you my webhook"

game.Players.PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function(msg)
		local args = msg:split(" ")
		local plruser = args[2]
		local reason = args[3]
		local user = game.Players:FindFirstChild(plruser)
		
		if args[1] == "-warn" and plr:GetRankInGroup(33075577) >= 228 then
			if user.Warns then
				if user.Warns.Value == 3 then
					plr:Kick("You've reached 3 warns.")
				end
				user.Warns.Value += 1
				local fields = {
					{
						['name'] = "Info",
						['value'] = "User: "..plr.Name, "Rank: **"..plr:GetRoleInGroup(33075577).."**",
						['inline'] = true
					},
					{
						['name'] = "Warn Info",
						['value'] = "User Warned "..user.." for "..reason.." Now has "..user.Warns.Value
					}
				}
				ws:createEmbed(url, "WARN", "This is published on 30/10/2023 9:57 pm by **RobloxSupp515**", fields)
			end
		end
	end)
end)
1 Like

On what line is the error on? 30 text thing

This could work:

local ws = require(script.Parent.WebhookService)
local url = "no am not giving you my webhook"

game.Players.PlayerAdded:Connect(function(plr)
    plr.Chatted:Connect(function(msg)
        local args = msg:split(" ")
        local plruser = args[2]
        local reason = table.concat(args, " ", 3) -- concatenate all arguments from the 3rd element to the end
        local user = game.Players:FindFirstChild(plruser)

        if args[1] == "-warn" and plr:GetRankInGroup(33075577) >= 228 then
            if user and user:FindFirstChild("Warns") then
                local warns = user.Warns.Value
                if warns == 3 then
                    plr:Kick("You've reached 3 warns.")
                else
                    user.Warns.Value = warns + 1
                    local fields = {
                        {
                            ['name'] = "Info",
                            ['value'] = "User: " .. plr.Name .. "\nRank: **" .. plr:GetRoleInGroup(33075577) .. "**",
                            ['inline'] = true
                        },
                        {
                            ['name'] = "Warn Info",
                            ['value'] = "User Warned " .. user.Name .. " for " .. reason .. "\nNow has " .. user.Warns.Value
                        }
                    }
                    ws:createEmbed(url, "WARN", "This is published on 30/10/2023 9:57 pm by **RobloxSupp515**", fields)
                end
            else
                plr:Kick("User not found or Warns folder not present.")
            end
        end
    end)
end)

Heres what I’ve done:

  1. Concatenated the reason using table.concat to ensure all words after the 3rd argument are combined into a single string.
  2. Added a check for the existence of the user and the Warns folder to avoid errors.
  3. Included line breaks in the “Info” field for better formatting.
  4. Provided a helpful message if the user is not found or the “Warns” folder is missing.

this part of the line, please check cuz this will be very cool for me

the variable user here refers to the actual player instance not a string.

The reason doesn’t show up anymore, can you fix this?

Here:

local ws = require(script.Parent.WebhookService)
local url = "no am not giving you my webhook"

game.Players.PlayerAdded:Connect(function(plr)
    plr.Chatted:Connect(function(msg)
        local args = msg:split(" ")
        local plruser = args[2]
        local reason = table.concat(args, " ", 3)
        local user = game.Players:FindFirstChild(plruser)

        if args[1] == "-warn" and plr:GetRankInGroup(33075577) >= 228 then
            if user and user:FindFirstChild("Warns") then
                local warns = user.Warns.Value
                if warns == 3 then
                    plr:Kick("You've reached 3 warns.")
                else
                    user.Warns.Value = warns + 1
                    local fields = {
                        {
                            ['name'] = "Info",
                            ['value'] = "User: " .. plr.Name .. "\nRank: **" .. plr:GetRoleInGroup(33075577) .. "**",
                            ['inline'] = true
                        },
                        {
                            ['name'] = "Warn Info",
                            ['value'] = "User Warned " .. user.Name .. " for " .. reason .. "\nNow has " .. user.Warns.Value
                        }
                    }
                    ws:createEmbed(url, "WARN", "This is published on 30/10/2023 9:57 pm by **RobloxSupp515**", fields)
                end
            else
                plr:Kick("User not found or Warns folder not present.")
            end
        end
    end)
end)

Would it not just be “user.Name” seeing as user is a Player object grabbed from “game.Players:FindFirstChild(plrusr)”

1 Like

seems the same, I tested it and it is still the same.

What was your error? Snapshots please.

Here is the error,

You’re trying to call FindFirstChild but the argument supplemented (plrusr) is nil, so it seems to me like the “args[2]” in your plrusr variable declaration doesn’t exist, and it’s clear to see why. You did “msg:split(” “)” instead of “msg.split(” “)”. So you’ve used : instead of .
Hope this works.

Actually apologies, I’ve looked at this wrong. msg.split is invalid syntax. You’d want "string.split(msg, " “)”

Attempt to concatenate Instance with string.
local user = … – user is defined as a player instance
[‘value’] = "User Warned “…user…” for " etc – user here is an instance
changed to user.Name to get user’s name as a string

Thank you! This works, I hope to see you again.

All good, glad it worked out in the end. Feel free to ping me here if you need any help and I’ll get back to you when I can :+1:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.