I have intvalues set up in my replicatedstorage with information in them, such as usernames and other values. But, when I try to print those values from a localscript, I am getting errors.
local val = game.ReplicatedStorage.Int2
local user = game.ReplicatedStorage.PlrValue
local plr = user.Value
local text = " Has Been Purchased By "
local amount = game.ReplicatedStorage.AmountValue
local amountVal = amount.Value
local combinedtext = amountVal .. text .. plr
val.Changed:Connect(function()
print (combinedtext)
end)
error: Players.Generic0001.PlayerGui.ScreenGui.TextLabel.LocalScript:6: attempt to concatenate Instance with string
Assuming plr is a Player instance, you can just do:
local combinedtext = amountVal .. text .. plr.Name
You can test whether the assumption is true by typing print(plr.ClassName) before that line. You can also guarantee it won’t error by wrapping each of the concatenated variables with tostring(), although that would really be a band-aid solution.
So there are two assumptions I’m making in total:
game.ReplicatedStorage.PlrValue is an ObjectValue, which means you would want to print the name of .Value.
game.ReplicatedStorage.AmountValue is a NumberValue or IntValue, which means .Value is just a number, which is allowed to be concatenated with strings.
I’m assuming amountVal is a may be an instance, rather then a string.
in that case I might suggest turning it into a string using the “tostring()” function.
first though, id recomend printing amountVal, text and plr each on different lines, to see whether or not any of them return nil.
local val = game.ReplicatedStorage.Int2
local user = game.ReplicatedStorage.PlrValue
local plr = user.Value
local text = " Has Been Purchased By "
local amount = game.ReplicatedStorage.AmountValue
local amountVal = amount
local combinedtext = amountVal.Value .. text .. plr.Name
val.Changed:Connect(function()
print (combinedtext)
end)