Attempt to concatenate string with nil. Fail to use write a value in a textLabel

(please tell me if it’s the wrong category)
Hello,
I have a problem with my datastore2 script:

  1. the output say “attempt to concatenate string with nil” but i don’t know how to fix this:

  2. Output:


    Explorer:
    image
    CurrencyServer script:

wait(game.Loaded)

local players = game:GetService("Players")
local replicatedstorage = game:GetService("ReplicatedStorage")

local Datastore2 = require(1936396537)

local defaultCurrencyAmount = 75

players.PlayerAdded:Connect(function(player)
	local currencyStore = Datastore2("Money", player)
	
	local function updateClientCurrency(amount)
		replicatedstorage.RemoteEvents.UpdateClientCurrency:FireClient(player, amount)
	end
	
	updateClientCurrency(currencyStore:Get(defaultCurrencyAmount))
	
	currencyStore:OnUpdate(updateClientCurrency())
end)

while wait(10) do
	for k, v in pairs(players:GetChildren()) do
		local currencyStore = Datastore2("Money", v)
		
		currencyStore:Increment(1)
	end
end

ClientCurrencyGUI script:

wait(game.Loaded)

local replicatedstorage = game:GetService("ReplicatedStorage")

replicatedstorage.RemoteEvents.UpdateClientCurrency.OnClientEvent:Connect(function(amount)
	script.Parent.Text = amount
end)

If you want to see the module that i use (datastore2)

  1. So i want to know how to fix this because then the value doesn’t update…
    the fail is this line: (line 6 in the output)
script.Parent.Text = amount

So, i don’t know why it fails because the server script fireClient a remote event of a value, the localScript register the value and change the text to the value.
(value is the “amount”)

Have a good day !

2 Likes

Nil is a data type so its like trying to do “string”…false in a sense. You can say if the input is nil then replace the concatination with " ", an empty string i guess

i tried but it doesn’t work. so i don’t know…

Try to use tostring(), this converts the number into a string.

Like this:
script.Parent.Text = tostring(amount)

2 Likes

thank you so mush :slight_smile: now my script work :))))

1 Like