Attempt to concatenate string with nil

Im trying to create a webhook system to send a rating for my game to a discord server.

Everything works fine exept the rating part.

Script:

local url = "i removed the webhook for safety purposes"
local http = game:GetService("HttpService")

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local folder = Instance.new("Folder", script)
folder.Name = "ratings"

ReplicatedStorage.FlightRating.RE.Main.OnServerEvent:Connect(function(plr)
	
	local function rating1()
		if plr.PlayerGui.FlightRating.Main.Rating1.Star5_Service_Image_Full.Visible == true then
			return "5"
		else
			if plr.PlayerGui.FlightRating.Main.Rating1.Star5_Service_Image_Half.Visible == true then
				return "4.5"
			else
				if plr.PlayerGui.FlightRating.Main.Rating1.Star4_Service_Image_Full.Visible == true then
					return "4"
				else
					if plr.PlayerGui.FlightRating.Main.Rating1.Star4_Service_Image_Half.Visible == true then
						return "3.5"
					else
						if plr.PlayerGui.FlightRating.Main.Rating1.Star3_Service_Image_Full.Visible == true then
							return "3"
						else
							if plr.PlayerGui.FlightRating.Main.Rating1.Star3_Service_Image_Half.Visible == true then
								return "2.5"
							else
								if plr.PlayerGui.FlightRating.Main.Rating1.Star2_Service_Image_Full.Visible == true then
									return "2"
								else
									if plr.PlayerGui.FlightRating.Main.Rating1.Star2_Service_Image_Half.Visible == true then
										return "1.5"
									else
										if plr.PlayerGui.FlightRating.Main.Rating1.Star1_Service_Image_Full.Visible == true then
											return "1"
										else
											if plr.PlayerGui.FlightRating.Main.Rating1.Star1_Service_Image_Half.Visible == true then
												return "0.5"
											else
												return "0"
											end
										end
									end
								end
							end
						end
					end
				end
			end
		end
	end
	
	local function rating2()
		if plr.PlayerGui.FlightRating.Main.Rating2.Star5_Service_Image_Full.Visible == true then
			return "5"
		else
			if plr.PlayerGui.FlightRating.Main.Rating2.Star5_Service_Image_Half.Visible == true then
				return "4.5"
			else
				if plr.PlayerGui.FlightRating.Main.Rating2.Star4_Service_Image_Full.Visible == true then
					return "4"
				else
					if plr.PlayerGui.FlightRating.Main.Rating2.Star4_Service_Image_Half.Visible == true then
						return "3.5"
					else
						if plr.PlayerGui.FlightRating.Main.Rating2.Star3_Service_Image_Full.Visible == true then
							return "3"
						else
							if plr.PlayerGui.FlightRating.Main.Rating2.Star3_Service_Image_Half.Visible == true then
								return "2.5"
							else
								if plr.PlayerGui.FlightRating.Main.Rating2.Star2_Service_Image_Full.Visible == true then
									return "2"
								else
									if plr.PlayerGui.FlightRating.Main.Rating2.Star2_Service_Image_Half.Visible == true then
										return "1.5"
									else
										if plr.PlayerGui.FlightRating.Main.Rating2.Star1_Service_Image_Full.Visible == true then
											return "1"
										else
											if plr.PlayerGui.FlightRating.Main.Rating2.Star1_Service_Image_Half.Visible == true then
												return "0.5"
											end
										end
									end
								end
							end
						end
					end
				end
			end
		end
	end
	
	local function rating3()
		if plr.PlayerGui.FlightRating.Main.Rating3.Star5_Service_Image_Full.Visible == true then
			return "5"
		else
			if plr.PlayerGui.FlightRating.Main.Rating3.Star5_Service_Image_Half.Visible == true then
				return "4.5"
			else
				if plr.PlayerGui.FlightRating.Main.Rating3.Star4_Service_Image_Full.Visible == true then
					return "4"
				else
					if plr.PlayerGui.FlightRating.Main.Rating3.Star4_Service_Image_Half.Visible == true then
						return "3.5"
					else
						if plr.PlayerGui.FlightRating.Main.Rating3.Star3_Service_Image_Full.Visible == true then
							return "3"
						else
							if plr.PlayerGui.FlightRating.Main.Rating3.Star3_Service_Image_Half.Visible == true then
								return "2.5"
							else
								if plr.PlayerGui.FlightRating.Main.Rating3.Star2_Service_Image_Full.Visible == true then
									return "2"
								else
									if plr.PlayerGui.FlightRating.Main.Rating3.Star2_Service_Image_Half.Visible == true then
										return "1.5"
									else
										if plr.PlayerGui.FlightRating.Main.Rating3.Star1_Service_Image_Full.Visible == true then
											return "1"
										else
											if plr.PlayerGui.FlightRating.Main.Rating3.Star1_Service_Image_Half.Visible == true then
												return "0.5"
											end
										end
									end
								end
							end
						end
					end
				end
			end
		end
	end
	
	local rating1data = rating1()
	local rating2data = rating2()
	local rating3data = rating3()
	
	
	local data = {
		['embeds'] = {{
			['title'] = "New Rating from "..plr.Name,
			['description'] = "Service: "..rating1data,
			['color'] = 3769131,
			['url'] = "https://www.roblox.com/isers/"..plr.UserId.."/profile"
			
		}}
	}
	
	local finaldata = http:JSONEncode(data)
	http:PostAsync(url, finaldata)
end)

The thing is now it only returns “0” to the embed. Even tho for the player the 5 star is visible.

Please help.

Which particular line is erroring?

The description part of the script

That means the function named “rating1” isn’t returning a valid string value.

How would I fix that tho? idk anymore really

Just make it return a value by default (if no other value is returned). Here’s an example.

local function GiveValue()
	if Condition1 then
		return 1
	elseif Condition2 then
		return 2
	end
	return 3 --Default.
end

so rating1data is nil for whatever reason even though you are returning a value?

maybe do rating1()

local rating1data = rating1()

try printing rating1data

It decides to print 0 even tho i selected it so it is 5 stars

wait are you changing star visibility on local script cause it won’t detect it on server

You need to fix the else chains so that they’re all contained within the same chain.

this is in a serverscript so i suppose im checking on the server

if plr.PlayerGui.FlightRating.Main.Rating2.Star5_Service_Image_Full.Visible == true then
	return "5"
elseif plr.PlayerGui.FlightRating.Main.Rating2.Star5_Service_Image_Half.Visible == true then
	return "4.5"
elseif plr.PlayerGui.FlightRating.Main.Rating2.Star4_Service_Image_Full.Visible == true then
	return "4"
elseif plr.PlayerGui.FlightRating.Main.Rating2.Star4_Service_Image_Half.Visible == true then
	return "3.5"
--and the rest follow

Here’s what I mean by that.

1 Like

The server cannot see client side changes made to the gui so I presume that it sees the default rating which is none visible.

You need to send maximum star rating that the player has to the server or figure out another way.

How would I do this tho? Like i tried it before but didnt succeed

I fixed else chains but now its the ui changes thing

you would basically do the same thing you are doing in this serverevent but move all functions to the client where you fire to the server, you then pass the associated ratings as parameters

(you would also need to make reasonable checks on server, you dont want someone to put rating = “100”)

local function rating1()
	if Rating1.Star5_Service_Image_Full.Visible == true then
		return "5"
	elseif Rating1.Star5_Service_Image_Half.Visible == true then
		return "4.5"
	elseif Rating1.Star4_Service_Image_Full.Visible == true then
		return "4"
	elseif Rating1.Star4_Service_Image_Half.Visible == true then
		return "3.5"
	elseif Rating1.Star3_Service_Image_Full.Visible == true then
		return "3"
	elseif Rating1.Star3_Service_Image_Half.Visible == true then
		return "2.5"
	elseif Rating1.Star2_Service_Image_Full.Visible == true then
		return "2"
	elseif Rating1.Star2_Service_Image_Half.Visible == true then
		return "1.5"
	elseif Rating1.Star1_Service_Image_Full.Visible == true then
		return "1"
	elseif Rating1.Star1_Service_Image_Half.Visible == true then
		return "0.5"
	end
	return "0"
end

Main.SendBtn.MouseButton1Click:Connect(function(rating1)
	rating1 = rating1()
	game.ReplicatedStorage.FlightRating.RE.Main:FireServer(rating1)
end)

This is what im doing on the client? doesnt seem to work

Rating1 is a folder inside the ui and i’ve called it with a local

you need to provide serverscript changes as well as you are doing it correctly right now at least in this local script hold up you forgot the else at the bottom of the elseif block
elseif Rating1.Star1_Service_Image_Half.Visible == true then
return “0.5”
else
return “0”

ReplicatedStorage.FlightRating.RE.Main.OnServerEvent:Connect(function(plr, rating1)
	
	local data = {
		['embeds'] = {{
			['title'] = "New Rating from "..plr.Name,
			['description'] = "Service: "..rating1,
			['color'] = 3769131,
			['url'] = "https://www.roblox.com/users/"..plr.UserId.."/profile",
			['fields'] = {
				['name'] = "Feedback:",
				['value'] = plr.PlayerGui.FlightRating.Main.FeedbackBox.Text
			}
			
		}}
	}
	
	local finaldata = http:JSONEncode(data)
	http:PostAsync(url, finaldata)
end)```

try adding prints for rating1 so we can see whats up also make sure to add the else return “0” i mentioned

Players.AviaTeamm.PlayerGui.FlightRating.ClientSideCore:443: attempt to call a nil value