How do I stop my projectiles from dropping the client to 20 fps when shooting

projectile code:

local steps = 1000

steps = math.clamp(steps,1,math.huge)

while task.wait() do
	
	for _,v in workspace:WaitForChild("ClientBullets"):GetChildren() do
		
		for _,v1 in workspace:WaitForChild("ReplicatedBullets"):GetDescendants() do
			if v:FindFirstChild("Id") then
				
				local id = v1:FindFirstChild("Id")

				if id then
					if id.Value == v.Id.Value then
						--	v:Destroy()
						v1.BrickColor = BrickColor.White()
						v1.Transparency = 0
						v1.Size=v.Size-Vector3.new(.1,.1,-.1)
					end
				end
				
			end
			
		end
		
		spawn(function()
			

			local cur = 0
			repeat
				task.wait()
				cur+=1
				
				local id = v:FindFirstChild("Id")
				if v and id then
					id = id.Value
					
					v.Position+=(v.CFrame.LookVector*(1))

					v.Orientation-=Vector3.new(workspace.Gravity/10000,0,0)
					v.Orientation = Vector3.new(math.clamp(v.Orientation.X,-180,90),v.Orientation.Y,v.Orientation.Z)

					--Parent:WaitForChild("RemoteEvent"):FireServer({Action = "Update",Id = id,CF = v.CFrame})

					local p = RaycastParams.new()
					p.FilterType = Enum.RaycastFilterType.Exclude
					p.FilterDescendantsInstances = {Character}

					local r = workspace:Raycast(v.Position,v.CFrame.LookVector*cur)

					if r then
						local tar = r.Instance


						Parent:WaitForChild("RemoteEvent"):FireServer({Action = "Hit",Id = id,LookVector = v.CFrame.LookVector,Target = tar,Projectile = v,Steps = steps})

						if tar.Anchored then
							v:Destroy()
						end
					end
					
				end
				
			until cur >= steps or not v
			
		end)

	end


end

the longer one exists the more it lags until it destroys itsefl from this part whichc reates bulets in client too:

local Direction = Mouse.Hit.Position
	local pos = nil

	for _,v in Parent:GetDescendants() do
		if v.Name == "FirePos" and v:IsA("BasePart") then
			pos = v
		end
	end

	local obj = game:GetService("ReplicatedStorage"):WaitForChild("Bullet"):Clone()	
	obj.Position = pos.Position		
	obj.CFrame = CFrame.lookAt(pos.Position,Direction)

	obj.Position+=obj.CFrame.LookVector*obj.Size.Z
	
	local i = Instance.new("StringValue")
	i.Name = "Id"
	i.Value = math.random(1,9999999).."-"..math.random(1000,9999)
	i.Parent = obj
	
	obj.Parent = workspace:WaitForChild("ClientBullets")
	
	
--	table.insert(CurrentBullets,obj)

	spawn(function()
		wait(2)
	--	table.remove(CurrentBullets,table.find(CurrentBullets,obj))
		obj:Destroy()
	end)

it’s probably lagging because of the task.wait() loop which moves bullets, is there a better way to do it cuz it’s way too laggy and not even that configurable

You’re probably best off using Fast Cast, seems to fix your issue:

I did alreay find a soulution but I’ll check this out (I used solution I found since I;fastcast confusing)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.