I’m working on my new shop system, and I want to return the results of the transactions, for example:
Player request a sword to buy
Server checks if the player already bought the sword
Return result: “Player already bought the sword”
The problem is that I’m getting an error (Server and client):
Attempt to concate nil with String
The server script example:
local function x(Player, Argument)
local Item = Shop[Argument]
if Item then
if Player.Objects[Item.Name] then
return "Object is real"
else
return "You don't have the object"
end
end
end
ServerEvent.OnServerInvoke = x
Currently, I can’t give the script because I’m on Mobile right now, if you need more information to help me, you can ask me then.
I don’t know why this is happening, I didn’t find any article in the developer hub.
I would assume Item is non-existent, which then the function would return nil.
To confirm this is the case, add a random return statement outside of your condition scope-
local function x(Player, Argument)
local Item = Shop[Argument]
if Item then
if Player.Objects[Item.Name] then
return "Object is real"
else
return "You don't have the object"
end
end
return "Item is not existent"
end
Client script is basically a code requesting to buy something and waiting for a response (returning something), and change a text with the response. I dont think there is more stuff to explain, but I will try to get the code.
What do you mean when I’m attempting to combine a string with nil?
You’re setting AddItem.Name = ItemID but later on you’re using ItemID as a dictionary.
which leads me to believe ItemID is a string and not a dictionary giving you the error.
-- ItemID is not a dictionary but appears to be a string
return "I've bought "..ItemID.."!"
OR
If your Item declaration contains a “Name” property you could use that instead
return "I've bought "..Item["Name"].."!"
Since its a concatenation error string with nil; I’m guessing Item[‘Name’] is non-existant, so it has no value defined under the key ‘Name’.