Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Changing surface ui according to value?

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)

5 comments

0

Did you defined the ObjectValue value?

0

yes

0

What is the object value referencing to?

0

Its referencing the player's name

0

Try obj.Value.Name instead.

2 answers

✓ Accepted answer

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!

1 comment

0

Yay thanks for the help :) It works now

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)


1 comment

0

Ok that must have been the problem there. But now i have an error saying: invalid argument #3 (string expected, got instance)

This discussion is preserved as it was. New answers, comments, and votes are closed.