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

button gui not changing values?

im trying to make a script in a button gui that when i click it, it changes a value to the gui's name but right now it leaves the value to "None" in the output it prints : 1 2 and if i click again it prints 1 3 any idea whats wrong?

repeat wait(1)
player = game.Players.LocalPlayer
until player

local holding = script.Parent.Parent.Parent.Parent.HoldingItem.Value
local item = script.Parent
function OnClicked()
	print("1")
	if holding ~= item.Name then
		print("2")
		holding = item.Name
	elseif holding == item.Name then
		print("3")
		holding = "None"
	end
end

script.Parent.MouseButton1Click:Connect(OnClicked)

1 comment

1

In your code, holding is the value of the holding item when you first run the code. Its not the holding object itself. Try taking away the ".Value" from line 5 and changing "holding" to "holding.Value" in lines 9, 11, 12, and 14.

1 answer

✓ Accepted answer

If you want to change the value, you're going to have to define holding as script.Parent.Parent.Parent.Parent.HoldingItem and then use holding.Value where you're reading from or writing to it.

--The repeat loop here was unnecessary
player = game.Players.LocalPlayer

local holding = script.Parent.Parent.Parent.Parent.HoldingItem
local item = script.Parent
function OnClicked()
    print("1")
    if holding.Value == item.Name then
        print("3")
        holding.Value = "None"
     else --Use an else statement. This code will run if holding.Value is not item.Name
        print("2")
        holding.Value = item.Name
    end
end

script.Parent.MouseButton1Click:Connect(OnClicked)

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