I am trying to change the test of a surface ui according to a value. So basically, i have an object value, and i need the value written onto a surface ui. This is my coding and its not working:
ServerScript:
local obj = script.Parent.Obj local label = script.Parent.Label.SurfaceGui.TextLabel.Text game.Players.PlayerAdded:Connect(function() if obj.Value ~= nil then label = obj.Value end end)
No errors or anything, no spelling mistakes or wrong references. How could i make this work?
Edit: I have solved the problem in this script, but a new problem was created:
This is my script now:
local obj = script.Parent.Obj local label = script.Parent.Label.SurfaceGui.TextLabel game.Players.PlayerAdded:Connect(function() if obj.Value ~= nil then label.Text = obj.Value end end)
Now i have an error : invalid argument #3 (string expected, got Instance)
Well, you are trying to convert Instance
to a String
. And the Value
in ObjectValue
is actually an Instance
. To fix the issue :
-- Line 6, instead of label.Text = obj.Value -- Make it label.Text = obj.Value.Name
Lemme know if it helps!
The label
should hold reference to the TextLabel
object for it to work. However label
in your script is just a string
. Therefore in the function, you are just changing that string to other one.
label
holds that new string, but it is just an internal script variable. Here is how it should be done.
local obj = script.Parent.Obj local label = script.Parent.Label.SurfaceGui.TextLabel --remove .Text game.Players.PlayerAdded:Connect(function() if obj.Value ~= nil then label.Text = obj.Value --add .Text here end end)