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

How do I refer to values in gui from a normal script?

Asked by 2 years ago

So I'm making a lumber game, in which there is a function to sell your wood for cash. What I'm trying to do here is for the value of wood inside of the inventory gui to return to 0 and for cash (the leaderstat) to go up reasonably. I just can't figure out what's wrong.

script.Parent.Touched:connect(function(part)
    local plr = game.Players:GetPlayerFromCharacter(part.Parent)
    local cash = plr.leaderstats.Cash
    local gui = plr.PlayerGui.inventory
    local woodvalue = gui.frame.wood.value

    if woodvalue.Value ~= 0 then

        cash.Value = cash.Value + woodvalue.Value
        woodvalue.Value = 0

    end
end)    
0
So what's the problem? Is the wood value not going to 0 or the cash not going up reasonably or both? boredlake 256 — 2y
0
I mean, for one thing, "woodvalue.value" doesn't seem to exist, since you defined woodvalue to be the value of the wood, so you're asking for the value of a value, which doesn't really work. I could be wrong but that's what it looks like. AbettrWesley 6 — 2y
0
Woodvalue is a stringvalue inside of a playergui, which i'm trying to contact from this script, which is in a part located in Workspace. tottero5 0 — 2y
0
I believe that the problem is that woodvalue isn't answering. tottero5 0 — 2y
View all comments (2 more)
0
In your definition of woodvalue is wood the StringValue or is value the StringValue? boredlake 256 — 2y
0
Woodvalue is the stringvalue. The stringvalue is called "value", so therefore I have to refer it as value.Value. tottero5 0 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago

you have:

    if woodvalue.Value ~= 0 then

        cash.Value = cash.Value + woodvalue.Value
        woodvalue.Value = 0

I did not get a chance to fully test this but i'd imagine that your error is that roblox does not like having 2 different values to add (try assigning them to variables or do the following)

try replacing the top code with:

    if woodvalue.Value ~= 0 then

        cash.Value += woodvalue.Value
        woodvalue.Value = 0

0
It didn't work, but I do believe that is the problem. tottero5 0 — 2y
0
I think the problem is that you are adding a 'Number' value with a 'String' value ABDULGHANI1010 5 — 2y
Ad

Answer this question