Hi, so I am trying to make a detector where the local script detects how close the player is to the eggs in the folder
So the issue is that the detector is suppose to detect how close the player character is to the all the eggs in the folder but instead it only detects one of the eggs from the folder.
RunService.Heartbeat:Connect(function()
for i, v in pairs(workspace.Eggs:GetChildren())do
if (v.PrimaryPart.Position - player.Character.HumanoidRootPart.Position).Magnitude <= 8 then
if deb == false then deb = true
local frame = player["PlayerGui"]["onTouchGui"]["Selections"]["EggOpenFrame"]
frame["canActivate"].Value = true
frame["EggName"].Value = v.Name
TweenModule.TweenFrame(frame, {Position = UDim2.new(0.5, 0,0.5, 0)}, 0.25)
end
else
if (v.PrimaryPart.Position - player.Character.HumanoidRootPart.Position).Magnitude > 8 then
local frame = player["PlayerGui"]["onTouchGui"]["Selections"]["EggOpenFrame"]
frame["canActivate"].Value = false
TweenModule.TweenFrame(frame, {Position = UDim2.new(0.5,0,1.5,0)}, 0.25)
deb = false
end
end
end end)
now the script doesn’t detector any eggs in the folder
RunService.Heartbeat:Connect(function()
for i, v in pairs(workspace.Eggs:GetChildren())do
if (v.PrimaryPart.Position - player.Character.HumanoidRootPart.Position).Magnitude <= 8 then
if not deb[v] then deb[v] = true
local frame = player["PlayerGui"]["onTouchGui"]["Selections"]["EggOpenFrame"]
frame["canActivate"].Value = true
frame["EggName"].Value = v.Name
end
else
if (v.PrimaryPart.Position - player.Character.HumanoidRootPart.Position).Magnitude > 8 then
local frame = player["PlayerGui"]["onTouchGui"]["Selections"]["EggOpenFrame"]
frame["canActivate"].Value = false
deb[v] = false
end
end
end
end)
RunService.Heartbeat:Connect(function()
for i, v in pairs(workspace.Eggs:GetChildren())do
if (v.PrimaryPart.Position - player.Character.HumanoidRootPart.Position).Magnitude <= 8 then
if deb[v] == nil or deb[v] == false then deb[v] = true
local frame = player["PlayerGui"]["onTouchGui"]["Selections"]["EggOpenFrame"]
frame["canActivate"].Value = true
frame["EggName"].Value = v.Name
end
else
if (v.PrimaryPart.Position - player.Character.HumanoidRootPart.Position).Magnitude > 8 then
local frame = player["PlayerGui"]["onTouchGui"]["Selections"]["EggOpenFrame"]
frame["canActivate"].Value = false
deb[v] = false
end
end
end
end)
i changed/ re-wrote your script, try this instead:
local Debounces = {}
while true do
wait(0.1)
for i, v in pairs(workspace.Eggs:GetChildren())do
if Debounces[v] == nil then
Debounces[v] = false
end
if Debounces[v] == false and (v.PrimaryPart.Position - player.Character.HumanoidRootPart.Position).Magnitude <= 8 then
Debounces[v] = true
local frame = player["PlayerGui"]["onTouchGui"]["Selections"]["EggOpenFrame"]
frame["canActivate"].Value = true
frame["EggName"].Value = v.Name
TweenModule.TweenFrame(frame, {Position = UDim2.new(0.5, 0,0.5, 0)}, 0.25)
else
if (v.PrimaryPart.Position - player.Character.HumanoidRootPart.Position).Magnitude > 8 then
local frame = player["PlayerGui"]["onTouchGui"]["Selections"]["EggOpenFrame"]
frame["canActivate"].Value = false
TweenModule.TweenFrame(frame, {Position = UDim2.new(0.5,0,1.5,0)}, 0.25)
Debounces[v] = false
end
end
end
end