Sup, developers! i wasted 5 hours already trying to understand whats going wrong with my script so here it is:
for _, rock in claimedRocksFolder:GetChildren() do
local proximityPrompt = rock:FindFirstChild("ProximityPrompt")
if proximityPrompt then
proximityPrompt.Triggered:Connect(function(player)
print(1)
local rockName = rock.Name
local ownerId = tonumber(rockName:match("%d+"))
local playerId = player.UserId
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local root = character:WaitForChild("HumanoidRootPart")
if tonumber(ownerId) == tonumber(playerId) then
if not carrying then
onCarry(rock, humanoid, root)
else
unCarry(rock, humanoid)
end
end
end)
end
end
I already know how to fix that(probably not the best idea) but if i will write
wait()
right after for _, rock in claimedRocksFolder:GetChildren() do
everything will work great but without wait() Triggered
just wont work. I wanna ask you maybe you know some tips that can help me or some ways that i can use to finish this code. i dont really wanna to use wait() cause ig it might just broke sometime on some laggy servers. btw its a server script in a serverScriptService. I already tried to use remote events, remote functions, already used different ways like claimedRocksFolder.ChildAdded:Connect(function() end)
and etc(even local script) so i got no idea more what i can do. my best guess is that adding wait() causes a short delay, which gives enough time for all the components to set up correctly(dont know maybe it will help)