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

For i v in pairs returning only the 2nd value of a table?

Asked by 5 years ago
Edited 5 years ago

So i made a "E to interact" localscript. The table "interactables" is where the objects that i want the player to interact are stored :

--VARIABLES
local plr = game.Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local mouse = plr:GetMouse()

mouse.TargetFilter = workspace:WaitForChild("Terrain")

local interactDistance = 5
local canInteract = false

local interactables = {workspace.Can, workspace.Poubelle}

repeat wait() until plr.Character ~= nil

local char = plr.Character
local debounce = false

game:GetService("UserInputService").InputBegan:connect(function(key)
    if debounce == true then return end
    debounce = true
    if key.KeyCode == Enum.KeyCode.E and canInteract == true then

if objName == "Can" then
    local takeTrashEvent = ReplicatedStorage:WaitForChild("TakeTrashEvent")
    takeTrashEvent:FireServer(obj)
end
    end
debounce = false
end)

while wait() do
    for i, part in pairs(interactables) do
        if (part.Position - char.UpperTorso.Position).magnitude < interactDistance and mouse.Target == part then
            canInteract = true
            objName = part.Name
            obj = part
            plr.PlayerGui.HUD.Tooltip.Text = "Press E to take ".. part.Name

if part.Name == "Poubelle" then
     plr.PlayerGui.HUD.Tooltip.Text = ("Press E to throw your wastes".." ("..obj.Space.Value.." / "..obj.MaxSpace.Value..")")
end

            plr.PlayerGui.HUD.Tooltip.Visible = true
        else
            canInteract = false

            plr.PlayerGui.HUD.Tooltip.Visible = false
        end
    end
end

But when I test the game, the Tooltip (Press E to take...) only shows up when I look at the 2nd object stored in the table...

0
Why is line 40 wrapped in brackets? Remove them. User#19524 175 — 5y
2
it doesn't matter ^^ User#20388 0 — 5y
1
yeah it doesnt change anything TheBuildex -9 — 5y

Answer this question