I'm trying to make a shop pop up when the player touches the shop. What the code is doing is that it goes through every single body part, checks if it has the function :GetTouchingParts(), inserting it into a table, checking if the table contains any object with the name of "ShopHitbox" and setting plrInteractedWithHitbox to true. Why does this not work?
Code:
local char = script.Parent
local plr = game.Players:GetPlayerFromCharacter(char)
local plrGui = plr.PlayerGui
local plrInteractedWithHitbox = false
while not plrInteractedWithHitbox do
local touchingParts = {}
for i, v in pairs(char:GetChildren()) do
if pcall(function() local t = v:GetTouchingParts() end) then
table.insert(touchingParts, i + 1, v:GetTouchingParts())
end
end
for i, v in pairs(touchingParts) do
if v.Name == 'ShopHitbox' then
plrInteractedWithHitbox = true
end
end
if plrInteractedWithHitbox == true then
print('test')
end
wait()
end

5 comments
Is this code in the while loop or just copy and paste this?
As in, can you show me what all the code will look like when I put it in?
Yes, that is the second for loop in the while loop.
I've copied and pasted this, but it doesn't work and I switched it to a local script and still not working. Anything to do?
I'll try to look deeper into this.