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

Why won't my script work when I click the object? [UNANSWERED]

The script is for a inventory system whenever I click the water bottle on the ground its suppose to find the player go to the GUI in the players playergui and see if Item1 through item5 are available and the first one it finds the text and the string value should be the item name

scripts here

script.Parent.ClickDetector.MouseClick:connect(function(plr)
    script.Parent.StringValue.Value = plr.Name
	if plr.PlayerGui.Inventory.Frame.Item1.Taken.Value == "NonTaken" then
		plr.PlayerGui.Inventory.Frame.Item1.ItemName.Value = "Bottle Water"
	elseif
		plr.PlayerGui.Inventory.Frame.Item1.Taken.Value == "Taken" then
	if
		plr.PlayerGui.Inventory.Frame.Item2.Taken.Value == "Nontaken" then
		plr.PlayerGui.Inventory.Frame.Item2.ItemName.Value = "Bottle Water"
	elseif
		plr.PlayerGui.Inventory.Frame.Item2.Taken.Value == "Taken" then
	if
		plr.PlayerGui.Inventory.Frame.Item3.Taken.Value == "NonTaken" then
		plr.PlayerGui.Inventory.Frame.Item3.ItemName.Value = "Bottle Water"
	elseif
		plr.PlayerGui.Inventory.Frame.Item3.Taken.Value == "Taken" then
	if
		plr.PlayerGui.Inventory.Frame.Item4.Taken.Value == "NonTaken" then
		plr.PlayerGui.Inventory.Frame.Item4.ItemName.Value = "Bottle Water"
	elseif
		plr.PlayerGui.Inventory.Frame.Item4.Taken.Value == "Taken" then
	if
		plr.PlayerGui.Inventory.Frame.Item5.Taken.Value == "NonTaken" then
		plr.PlayerGui.Inventory.Frame.Item5.ItemName.Value = "Bottle Water"
	elseif
		plr.PlayerGui.Inventory.Frame.Item5.Taken.Value == "Taken" then
		script.Parent:remove()
	end
	end
	end
	end
	end
	end)

1 answer

The first error was within 5 through 7. You could have added and, and it would work better. What you're telling ROBLOX is to basically cancel all the other elseif's.

script.Parent.ClickDetector.MouseClick:connect(function(plr)
	if plr.PlayerGui.Inventory.Frame.Item1.Taken.Value == "NonTaken" then
		plr.PlayerGui.Inventory.Frame.Item1.ItemName.Value = "Bottle Water"
	elseif
		plr.PlayerGui.Inventory.Frame.Item1.Taken.Value == "Taken" and plr.PlayerGui.Inventory.Frame.Item2.Taken.Value == "Nontaken" then
		plr.PlayerGui.Inventory.Frame.Item2.ItemName.Value = "Bottle Water"
	elseif
		 plr.PlayerGui.Inventory.Frame.Item2.Taken.Value == "Taken" and  plr.PlayerGui.Inventory.Frame.Item3.Taken.Value == "NonTaken" then
		plr.PlayerGui.Inventory.Frame.Item3.ItemName.Value = "Bottle Water"
	elseif
		plr.PlayerGui.Inventory.Frame.Item3.Taken.Value == "Taken" and plr.PlayerGui.Inventory.Frame.Item4.Taken.Value == "NonTaken" then
		plr.PlayerGui.Inventory.Frame.Item4.ItemName.Value = "Bottle Water"
	elseif
		plr.PlayerGui.Inventory.Frame.Item4.Taken.Value == "Taken" and plr.PlayerGui.Inventory.Frame.Item5.Taken.Value == "NonTaken" then
		plr.PlayerGui.Inventory.Frame.Item5.ItemName.Value = "Bottle Water"
	elseif
		plr.PlayerGui.Inventory.Frame.Item5.Taken.Value == "Taken" then
		script.Parent:Destroy()
	end
end)

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