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

Can anyone explain why random tables are appearing in this code?

Asked by 6 years ago
Edited 6 years ago

Good morning fellow (much better),scripters! Its going great but i have a problem.... I'm writing a piece of code which is not working at one point! I want to try and make it post a part's name so i can get its parent - but instead it shows a table the output is literally table: 34F44CB8... Can anyone explain this to me?

-goku:D

local player = game.Players.LocalPlayer 
local desaa = false

punchanimation = Instance.new("Animation")
punchanimation.AnimationId = "http://www.roblox.com/Asset?ID=2497648378"


local ipit = game:GetService("UserInputService")
local char = game.Workspace:WaitForChild(player.Name)


ipit.InputBegan:Connect(function(input)

    if input.KeyCode == Enum.KeyCode.E and desaa == false then
        desaa = true
        local fadfa = char.Humanoid:LoadAnimation(punchanimation)
        fadfa:Play()
        wait(1.9)
        local touched = char.RightHand:GetTouchingParts() --table parts here
        print(touched)                                                          

        desaa = false   


    end
end)

1
line 19 and 20 ? GetTouchingParts returns an array User#5423 17 — 6y

1 answer

Log in to vote
1
Answered by 6 years ago

That table: 34F44CB8... is just the tables memory address. Attempting to directly print a table, function or thread will print the memory address. The good thing is you can loop through that table, and get the parts with ease.

for _, part in next, char.RightHand:GetTouchingParts() do
    -- 'part' will be a different touching part after each cycle.
    print(part)
end

What I am doing is looping through the touching parts, part will be a different part for each cycle. It loops for however many parts their are in the table returned by GetTouchingParts, for example if 3 parts were touching the loop would iterate 3 times. I then print the part and from there you can do what is necessary.

Ad

Answer this question