Attempt to index nil with 'Name'

Ok so I used to script but I lost all of my skill, I’ve returned and I’m having an error in my Discord Webhook. I keep getting "attempt to index nil with ‘Name’, here’s my code. (Normal Script)

local url = ""
local http = game:GetService("HttpService")
local Player = game.Players.LocalPlayer
	
game.Players.PlayerAdded:Connect(function()
	local data ={
		['embeds'] = {{
			['title'] = "New Member!",
			['description'] = Player.Name, "is our new member! Congrats 🥳"
		}}
	}
	
	local finaldata = http:JSONEncode(data)
	http:PostAsync(url, finaldata)
	
end)

Hope you can help, thanks!

2 Likes

I am guessing that this isn’t a local script
we can get the player using PlayerAdded

local http = game:GetService("HttpService")
local players = game:GetService("Players")

local url = ""

players.PlayerAdded:Connect(function(player)
	local data = {
		embeds = {{
			title = "New Member!",
			description = player.Name.."is our new member! Congrats 🥳"
		}}
	}
	
	http:PostAsync(url, http:JSONEncode(data))
end)

EDIT:
fixed the code

2 Likes

Try this:

local url = ""
local http = game:GetService("HttpService")
	
game.Players.PlayerAdded:Connect(function(Player)
	local data ={
		['embeds'] = {{
			['title'] = "New Member!",
			['description'] = Player.Name, "is our new member! Congrats 🥳"
		}}
	}
	
	local finaldata = http:JSONEncode(data)
	http:PostAsync(url, finaldata)
	
end)

Why in studio it works on Discord, but in the real Roblox game the message doesn’t go through on discord?

I could be wrong, but I think discord removed webhooks

I thought they re-added it after roblox did some update. Roblox Discord Webhook Proxy Server

That’s from February 2018, you need to communicate with Discord through a proxy.

For future reference “game.Players.LocalPlayer” is nil in server scripts (isn’t defined).

1 Like

Yep I set one up, if anyone is curious on a tutorial here you go