Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Changing surface ui according to value?

Asked by 3 years ago
Edited 3 years ago

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)

0
Did you defined the ObjectValue value? yuni_Boy1234 320 — 3y
0
yes Superexperiencedguy 199 — 3y
0
What is the object value referencing to? sleazel 1287 — 3y
0
Its referencing the player's name Superexperiencedguy 199 — 3y
0
Try obj.Value.Name instead. sleazel 1287 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago

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!

0
Yay thanks for the help :) It works now Superexperiencedguy 199 — 3y
Ad
Log in to vote
1
Answered by
sleazel 1287 Moderation Voter
3 years ago

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)


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

Answer this question