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

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

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)	

6 comments

0

So what's the problem? Is the wood value not going to 0 or the cash not going up reasonably or both?

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.

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.

0

I believe that the problem is that woodvalue isn't answering.

0

In your definition of woodvalue is wood the StringValue or is value the StringValue?

0

Woodvalue is the stringvalue. The stringvalue is called "value", so therefore I have to refer it as value.Value.

1 answer

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

2 comments

0

It didn't work, but I do believe that is the problem.

0

I think the problem is that you are adding a 'Number' value with a 'String' value

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