Reputation: 1
While I was inside of Roblox Studio, I was making a script like the one before you:
local amount = 123
local Module = require(game.ServerScriptService:WaitForChild("Module"))
script.Parent.ClickDetector.MouseClick:Connect(function(player)
if player.leaderstats.Currency.Value >= amount then
player.leaderstats.Currency.Value = player.leaderstats.Currency.Value - amount
local pet = Module.chooseRandomPet()
--> print(pet.Name.." selected") <--
end
end)
When I went to use it I was greeted with "attempt to concatenate nil with string" around the area with the arrows.
What would I do in order to fix this hindrance.
Upvotes: 0
Views: 254
Reputation: 28950
Module.chooseRandomPet()
returns a table that has no field "Name"
. I'd guess that you get a simple Lua table where you expect to get a Roblox Instance. Or for some reason you managed to assign nil to that Instance's Name property.
Either way you should make find out why you don't what you expect. I found various petModule problems online. All of them had a lot of code in common that was full of mistakes.
If you cannot make sure that you don't get what you expect you should at least handle that case properly by checking if it's a nil value you're about to concatenate.
Upvotes: 1