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

Anyway to change StringValue based on TextLabel's text?

Asked by
R0jym 47
1 year ago
Edited 1 year ago

Hello there, I have a LocalScript where if a player presses a button the StringValue copies the current Text of the TextLabel, however it does not seem to work with any methods I could scavenge inside my head, what should I do?

NOTE: I used StringValue instead of IntValue for a specific reason

local user = game:GetService("Players").LocalPlayer
local button = user.PlayerGui.Roll.TextButton
local label = user.PlayerGui.Roll.TextLabel
local mainValue = user.PlayerGui.Roll.Value


button.MouseButton1Click:Connect(function()
    label.LocalScript.Disabled = true
    wait(1)
    if label.Text == "1" then
        mainValue.Value = "One"
    elseif label.Text == "2" then
        mainValue.Value = "Two"
    elseif label.Text == "3" then
        mainValue.Value = "Three"
    elseif label.Text == "4" then
        mainValue.Value = "Four"
    elseif label.Text == "5" then
        mainValue.Value = "Five"
    elseif label.Text == "6" then
        mainValue.Value = "Six"
    end
    label.LocalScript.Disabled = false
end)
0
what errors are u getting? are u sure disabling the local script isnt effecting ur script? ZeroToH3ro 82 — 1y
0
Even when I remove the line where the localscript disables it still doesn't work R0jym 47 — 1y

2 answers

Log in to vote
0
Answered by 1 year ago

It's not working because you are calling mainValue.Value.Value; mainValue is the Value itself.

Do mainValue = "One" instead of mainValue.Value = "One".

0
Still not working R0jym 47 — 1y
Ad
Log in to vote
0
Answered by 1 year ago

Be sure to use the output to check for errors, your new code should look like this:

local user = game:GetService("Players").LocalPlayer
local button = user.PlayerGui.Roll.TextButton
local label = user.PlayerGui.Roll.TextLabel
local mainValue = user.PlayerGui.Roll


button.MouseButton1Click:Connect(function()
    label.LocalScript.Disabled = true
    wait(1)
    if label.Text == "1" then
        mainValue.Value = "One"
    elseif label.Text == "2" then
        mainValue.Value = "Two"
    elseif label.Text == "3" then
        mainValue.Value = "Three"
    elseif label.Text == "4" then
        mainValue.Value = "Four"
    elseif label.Text == "5" then
        mainValue.Value = "Five"
    elseif label.Text == "6" then
        mainValue.Value = "Six"
    end
    label.LocalScript.Disabled = false
end)

Answer this question