hello I would like to make a loop that checks if a player is within a certain radius
the script itself works but when I put a music on, it repeats itself every two seconds because of the loop
so do you have an idea to put something else in place of "while true do"
script :
local Torso = script.Parent.Parent.Torso
sonic = script.Parent.Parent.Sonic
torsop = script.Parent.Parent.Torsoe
head = script.Parent.Parent.Heade
fly = script.Parent.Parent.SonicFly
lefta = script.Parent.Parent["Left Arm"]
righta = script.Parent.Parent["Right Arm"]
leftl = script.Parent.Parent["Left Leg"]
rightl = script.Parent.Parent["Right Leg"]
eye1 = script.Parent.Parent.Eyes1
eye2 = script.Parent.Parent.Eyes2
Chase = script.Parent.Chase
----------------------------------- BASIC ATTACK -------------------------------
-------------------------- Sonic kills and chase -------------------------------
while true do
for i,v in pairs(game.Players:GetChildren()) do
if (v.Character.Torso.Position - Torso.Position).magnitude <= 80 then
-- pos change
torsop.Transparency = 1
head.Transparency = 1
righta.Transparency = 1
lefta.Transparency = 1
leftl.Transparency = 1
rightl.Transparency = 1
fly.Transparency = 0
eye1.Transparency = 1
eye2.Transparency = 0
-- char change
sonic.WalkSpeed = 30
Chase:Play()
else
-- pos change
torsop.Transparency = 0
head.Transparency = 0
righta.Transparency = 0
lefta.Transparency = 0
leftl.Transparency = 0
rightl.Transparency = 0
fly.Transparency = 1
eye1.Transparency = 0
eye2.Transparency = 1
-- char change
sonic.WalkSpeed = 18
end
end
wait(2)
end
thanks for helping
EDIT : I also want to make sure that the sound is played for one person

1 comment
you can use repeat ... until false for infinite loops as well