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

No clue.. Not a master with tables.. Anyone know how to fix this?

Asked by 10 years ago
function OnHover(plr)
    if script.Parent:FindFirstChild("SelectionBox") == nil then
    f = Instance.new("SelectionBox")
    f.Parent = script.Parent
    f.Adornee = script.Parent
    if script.Parent:FindFirstChild("Humanoid") == nil then
    h = Instance.new("Humanoid")
    h.Parent = script.Parent.Parent
    h.MaxHealth = 0
    h.Health = 0
    script.Parent.Parent.Name = script.Parent.Parent.Name .. " [F]"
mouse = plr:GetMouse()
Slot1 = plr.PlayerGui.Inventory.Scrolling.Slot1
Slot2 = plr.PlayerGui.Inventory.Scrolling.Slot2
Slot3 = plr.PlayerGui.Inventory.Scrolling.Slot3
Slot4 = plr.PlayerGui.Inventory.Scrolling.Slot4
Slot5 = plr.PlayerGui.Inventory.Scrolling.Slot5
Slot6 = plr.PlayerGui.Inventory.Scrolling.Slot6
Slot7 = plr.PlayerGui.Inventory.Scrolling.Slot7
Slot8 = plr.PlayerGui.Inventory.Scrolling.Slot8
function Keys(key)
    key:lower()
    if key == "f" then

          -- Having trouble with the code below.
             if Slot1.Item.Value == "Nothing" or "Rock" then
        Slot1.Image = "http://www.roblox.com/asset/?id=167139238"
        Slot1.Item.Value = "Rock"
        elseif Slot1.Item.Value ~= "Nothing" or "Rock" then

        if Slot2.Item.Value == "Nothing" or "Rock" then
        Slot2.Image = "http://www.roblox.com/asset/?id=167139238"
        Slot2.Item.Value = "Rock"

        elseif Slot2.Item.Value ~= "Nothing" or "Rock" then
        if Slot3.Item.Value == "Nothing" then
        Slot3.Image = "http://www.roblox.com/asset/?id=167139238"
        Slot3.Item.Value = "Rock"

        -- It stops here.

    end





                    end
                end
            end
mouse.KeyDown:connect(Keys)
        end
    end
end





script.Parent.ClickDetector.MouseHoverEnter:connect(OnHover)


function OffHover()
if script.Parent:FindFirstChild("SelectionBox") ~= nil then
script.Parent.SelectionBox:remove()
if script.Parent.Parent:FindFirstChild("Humanoid") ~= nil then
script.Parent.Parent.Humanoid:remove()
-- if script.Parent.Parent.Name == "Rock [F]" then
script.Parent.Parent.Name = "Rock"
end
    end
end 



script.Parent.ClickDetector.MouseHoverLeave:connect(OffHover)

Now you see, the problem is, the image goes into the Gui and it goes in to all of them.

Anyone know a fix or maybe a way to add a table and test every slot to make sure it isn't equal to Rock or Nothing.

0
You spelled SelectionBox wrong on line 2. SlickPwner 534 — 10y
0
So I did. Thanks for noting that out. Can't believe I didn't notice that. legoguy939 418 — 10y
0
legoguy939: As a question asker, you should *accept* posts, even if you can't upvote them (green check mark) BlueTaslem 18071 — 10y

1 answer

Log in to vote
3
Answered by
Ekkoh 635 Moderation Voter
10 years ago
if Slot1.Item.Value == "Nothing" or "Rock" then

Has to be

if Slot1.Item.Value == "Nothing" or Slot1.Item.Value == "Rock" then

When you have the first, the if statement is actually checking two conditions. The first being Slot1.Item.Value == "Nothing", and the second being "Rock". In the case that Slot1.Item.Value does not equal "Nothing", the if statement will result to the expression after the or. Since "Rock" is neither nil nor false, it treats it as true, causing the whole expression to become true, causing the code inside the following scope to execute. So just make sure you explicitly state what you're comparing the value to, like so in the second example.

0
I'd upvote this but I can't because I have -1 rep. :( I'll see if this works. legoguy939 418 — 10y
Ad

Answer this question