Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Filtering Enabled Projectiles lag briefley?

I have this gun that uses a 2 script system to fire a projectile so it works in FE. in script 1 a Local script


--//LOCAL SCRIPT\\--
local tool = script.Parent
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local handle = tool:WaitForChild("Handle")
local remote = tool:WaitForChild("Shoot")

--//Events\\--
tool.Activated:Connect(function()
	print("Bang")
	remote:FireServer(mouse.hit.p)
end)

In script 2 a server script

--//Server Script\--

Handle=script.Parent:WaitForChild("Handle")
--//Server Script\\--

--FE Thing--
script.Parent.Shoot.OnServerEvent:Connect(function(player,Area)
--FE Thing--
	local Bullet = Instance.new("Part",workspace)
	Bullet.Name= "Bullet"
	Bullet.CanCollide= false
	Bullet.Shape = "Block"
  	Bullet.Material = "Neon"
  	Bullet.BrickColor = BrickColor.new ("Bright yellow")--Colour--
	Bullet.Size=Vector3.new (0.1,0.1,2)--Size--
	Bullet.CFrame = Handle.CFrame*CFrame.new(0,0,0)--Where--
	local Velo = Instance.new ("BodyVelocity",Bullet)
	Velo.velocity =  Bullet.CFrame.lookVector*300--Speed of Bullet--
	Velo.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
end)

I'm not sure why but when it fires the projectile it pauses for a brief second then moves. This makes it so you have to lead your shots more and sometimes at close range the bullet doesn't even damage people but just phases right through them.

I just want to know why it is does this and how do I stop it

3 comments

1

Use raycasting instead of body velocity.

1

well, maybe the reason it isnt doing damage is that you never programmed it to

0

lol

1 answer

✓ Accepted answer
  1. The part will phase through people because the CanCollide Property is set to false

  2. The delay in your script is because there is a brief delay when using Remote Events and Functions in order for them to properly receive information then enact the event

  3. As far as the damage issue, I can't really help with that unless that script / portion of the script was added to your question. However, you could try something like this:

Server Script placed in StarterCharacterScripts

local debounce = true

local function onTouch(hit)
if debounce == false then return end
debounce = false
	if hit.Name == "Bullet" then
		script.Parent.Humanoid.Health = 0
		print("Damaged")
		wait()
	end
debounce = true
end

for i, v in pairs(script.Parent:GetDescendants()) do
	if v:IsA("Part") or v:IsA("BasePart") or v:IsA("MeshPart") or v:IsA("UnionOperation") then
		v.Touched:Connect(onTouch)
	end
end

If you want to check out "RayCasting" as suggested by unsatisfie_d, you can find some information on that here: https://developer.roblox.com/articles/Raycasting

1 comment

0

Thanks this helped alot

This discussion is preserved as it was. New answers, comments, and votes are closed.