Hello!
I have created a proximity prompt so that a player can hide in a bush, however, it requires looping to see if any other players are hiding there. When I use a for loop though, it just doesn’t run. here is the script:
local plrsinbush = {}
script.Parent.Sphere.ProximityPrompt.Triggered:Connect(function(plr)
for i,v in pairs(plrsinbush) do
print("started")
if v == nil then
table.insert(plrsinbush, plr.Name)
plr.Character.HumanoidRootPart.CFrame = script.Parent.Sphere.CFrame
print("yues!")
elseif v then
return
end
end
end)
If there are no players in plrsinbush, as such the for loop will run at least 0 times… You need to add the players to plrsinbush before the for loop will run, not during it.
so from what i can see the table is empty so its not looping through anything therefore not running the code. try just checking if table.getn(table) = 0 instead of using the i,v loop that should work
use ipairs rather than pairs if you’re iterating through an array - from what it looks like, plrsinbush is an array (as shown with table.insert) so change pairs to ipairs
should mention from this post you should use #table instead of getn because getn is deprecated
local plrsinbush = {}
script.Parent.Sphere.ProximityPrompt.Triggered:Connect(function(plr)
if #plrsinbush == 0 then
table.insert(plrsinbush, plr.Name)
plr.Character.HumanoidRootPart.CFrame = script.Parent.Sphere.CFrame
print("yues!")
elseif v then
return
end
end
end)