I am using a while true do, and I have no idea how to stop it, I need to use a while true do for the rest of the script to work, if you could help that would be awesome its a roblox websling.
Code:
local statuses = {}
local webslingspeed = 2000
local tweens = game:GetService("TweenService")
local webzipspeed = 2500
local webreachspeed = .45
local radius = 3.5
local WebShootTime = 20
local WebShootSpeed = .2
local websize = 4
game:GetService("ReplicatedStorage").Web.OnServerEvent:Connect(function(plr, status, target, point, hand)
if status == true then
local char = plr.Character
if char then
local arm = char[hand.."Hand"] or char[hand.." Arm"]
local armattachment = Instance.new("Attachment")
armattachment.Parent = char.HumanoidRootPart
armattachment.WorldPosition = char.HumanoidRootPart.Position
local pointattachment = Instance.new("Attachment")
pointattachment.Parent = target
pointattachment.WorldPosition = point
local bodyGyro = Instance.new("BodyGyro")
bodyGyro.Parent = char.HumanoidRootPart
bodyGyro.P = 1000
bodyGyro.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
bodyGyro.D = 15
local rope = Instance.new("RopeConstraint")
local length = (arm.Position - point).Magnitude
rope.Visible = false
rope.Attachment0 = armattachment
rope.Attachment1 = pointattachment
rope.Parent = arm
rope.Length = length
rope.Color = BrickColor.new("White")
rope.Restitution = .5
task.wait()
local fakeattach = Instance.new("Attachment")
fakeattach.Parent = target
fakeattach.WorldPosition = char[hand.."Hand"].Position
local fakeattach2 = Instance.new("Attachment")
fakeattach2.Parent = char[hand.."Hand"]
fakeattach2.WorldPosition = char[hand.."Hand"].Position
local beam = Instance.new("Beam")
beam.Texture = "rbxassetid://8599205743"
beam.TextureMode = Enum.TextureMode.Stretch
beam.TextureSpeed = 0
beam.TextureLength = .1
beam.Transparency = NumberSequence.new(0)
beam.LightEmission = 1
beam.LightInfluence = 0
beam.FaceCamera = true
beam.Attachment0 = fakeattach2
beam.Attachment1 = fakeattach
beam.Width0 = 3
beam.Width1 = 3
beam.Parent = arm
local bodyForce = Instance.new("BodyForce")
bodyForce.Parent = char.HumanoidRootPart
local animator = char.Humanoid:WaitForChild("Animator")
local swing = animator:LoadAnimation(script:WaitForChild("Swing"))
spawn(function()
statuses[plr] = {armattachment, pointattachment, fakeattach, rope, bodyForce, bodyGyro, beam}
local tween = tweens:Create(fakeattach, TweenInfo.new(webreachspeed), {WorldPosition = point})
tween:Play()
tween.Completed:Connect(function()
beam.Attachment1 = pointattachment
end)
while true do
if char.Humanoid then
if statuses[plr] ~= nil then
swing:Play()
bodyGyro.CFrame = CFrame.new(char.HumanoidRootPart.Position, char.HumanoidRootPart.Position + char.Humanoid.MoveDirection * 10)
bodyForce.Force = Vector3.new(char.Humanoid.MoveDirection.X * webslingspeed, -webslingspeed / 10, webslingspeed / 5)
else
swing:Stop()
tween:Cancel()
end
else
swing:Stop()
tween:Cancel()
break
end
task.wait()
end
end)
end
elseif status == false then
if statuses[plr] ~= nil then
for _, v in pairs(statuses[plr]) do
v:Destroy()
end
statuses[plr] = nil
end
end
end)