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

My string value wont change twice?

Asked by
Paldi 109
10 years ago

i made an inventory gui with string values in it, when i click one of the slots it changes the string value in it but it wont change anymore, so if i remove the item in the slot, the value stays the same and wont change.

this is a part of the script to make you understand what it should do...

function OnClicked()
    local item = script.Parent.Parent.Parent.ItemName.Value
    local itemC = script.Parent.Parent.Parent.ItemClass.Value
    local itemA = script.Parent.Parent.Parent.ItemAmount.Value

if item == "None" then

    item = "Test"
    itemC = "Testing"
    itemA = "1"
elseif item  == "Test" then
       item = "None"
    itemC = "None"
    itemA = "0"
end
end

thats just an example of what it looks..

ps: this is in a local script

1 answer

Log in to vote
0
Answered by
Discern 1007 Moderation Voter
10 years ago

I remember making this exact error myself. You are setting the actual value of the StringValue as your variables, not the actual Instance itself. So what you are doing is this:

item = "None"

instead of

item = script.Parent.Parent.Parent.ItemName

Kind of confusing. To fix this, set your variables to the Instances and not the values, and then change all things in your script that says "item" to "item.Value".

Take a look:

function OnClicked()
    local item = script.Parent.Parent.Parent.ItemName
    local itemC = script.Parent.Parent.Parent.ItemClass
    local itemA = script.Parent.Parent.Parent.ItemAmount
    if item.Value == "None" then
        item.Value = "Test"
        itemC.Value = "Testing"
        itemA.Value = "1"
    elseif item.Value  == "Test" then
        item.Value = "None"
        itemC.Value = "None"
        itemA.Value = "0"
    end
end

I know it's a pain, but it is what it is.

0
Thank you! it worked! :D Paldi 109 — 10y
Ad

Answer this question