Attempt to index nil with 'Name'

Recently, I have been trying to create a Mod call system that when pressed, sends a message to a webhook with the players name, userid and reasoning of why they have pressed the button. When I press the button, I get prompted with “attempt to index nil with ‘Name’”. I am unsure as of why this is happening so I hope someone may help me. Thanks in advance! :slight_smile:

Code:

local http = game:GetService("HttpService")
local players = game:GetService("Players")
local player = game:GetService("Players").LocalPlayer
local url = "https://discordapp.com/api/webhooks/701207826592432148/Wlg8UCM2qJLox3ro6pqnY2oD1MSnfUWYrNM_JRBjHVYWaecJ6BBNbtxCf8uSs5vQGITg"
local reason = script.Parent.Reason

script.Parent.Call.MouseButton1Click:Connect(function(plr)
	local data = {
		["username"] = "Calling Moderator...",
		["content"] = "```".."Username: ".. plr.Name.."\n" .."User-Id: ".. plr.UserId.. "\n".. "Reason: ".. reason.Text
	}
	local newdata = http:JSONEncode(data)
	http:PostAsync(url,newdata)
end)
3 Likes

If this is a local script then you can just use the player variable rather than whatever that plr argument is.

1 Like

MouseButton1Click doesn’t return anything, so you won’t expect it to return the player. Just use the player variable you have defined, since this is a local script

This is a normal script and alright, but whenever I try do this, I get prompted with the same error.

1 Like

This cannot all work on one script. HTTP Requests can only be made by the server, and MouseButton1CLick will only work on the client. You’ll need the client to fire a remote event every time that the MouseButton1Click is fired, and then the server will do the HTTP request.

--client
local localPlayer = game:GetService("Players").LocalPlayer
local callRemote = game:GetService("ReplicatedStorage"):WaitForChild("Call")
script.Parent.Call.MouseButton1Click:Connect(function()
    call:FireServer(script.Parent.Reason)
end)
--server
local httpService = game:GetService("HttpService")
local call = Instance.new("RemoteEvent", game:GetService("ReplicatedStorage"))
local url = "https://discordapp.com/api/webhooks/701207826592432148/Wlg8UCM2qJLox3ro6pqnY2oD1MSnfUWYrNM_JRBjHVYWaecJ6BBNbtxCf8uSs5vQGITg"
call.Name = "Call"

call.OnServerEvent:Connect(function(plr, reason)
    local data = {
        ["username"] = "Calling Moderator...",
        ["content"] = "```".."Username: ".. plr.Name.."\n" .."User-Id: ".. plr.UserId.. "\n".. "Reason: ".. reason.Text
    }
    local newdata = http:JSONEncode(data)
    http:PostAsync(url,newdata)
end)

Edit: I have realized that script.Parent.Object is an instance. If you want the reason (which should be a string), you’ll want to do script.Parent.Object.Text if it’s a TextBox or script.Parent.Object.Value if it’s a StringValue

2 Likes

Wouldn’t suggest listening to the first few replies normally on feedback threads, as they’re mainly grabbers for first post.

Your issue is you’re doing this within a LocalScript, which cannot access HttpService.
You need to be using a RemoteEvent and have data passed to it, in which a Script can validate the data and send it through HttpService.

Alright thank you for this, I shall try it out to see if it works.

Normal scripts don’t have LocalPlayer, since it doesn’t run on a specified client. You’d have to use RemoteEvents for this - you’ll use a local script to handle the clicking, then you fire the event to the server to send the request, so ce http requests can’t be done on the client

1 Like