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

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

Asked by
Prioxis 673 Moderation Voter
10 years ago

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

Log in to vote
1
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
10 years ago

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)

Ad

Answer this question