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

How to fix ray casting delay?

Hello peoples. I am making a gun as I usually don't and I always run into the same problem, when running around or jumping, the ray is always like 3 or 4 studs away from the fire part of the gun. I have no idea how to fix this so any help is needed. Sorry for the short description. I'm not really sure what to say in this situation.

im just a scripting noob so plz help thx :D

This is the server script, the thing that shoots the ray: Just a little piece of it.

function fire(args)
	local gunInfo = getToolInfo(args[3])
	local ray = Ray.new(args[1].CFrame.Position, (args[2] - args[1].CFrame.Position).Unit * 300)
	local part, position = workspace:FindPartOnRayWithIgnoreList(ray, returnIgnoreList())
	local distance = (args[1].CFrame.Position - position).Magnitude
	local laser = Instance.new("Part")
	laser.Name = "Laser"
	laser.Size = Vector3.new(0.03, 0.03, distance)
	laser.CFrame = CFrame.new(args[1].CFrame.Position, position) * CFrame.new(0, 0, - distance/2)
	laser.BrickColor = BrickColor.new("Daisy orange")
	laser.Material = Enum.Material.Neon
	laser.Transparency = 0.35
	laser.CanCollide = false
	laser.CastShadow = false
	laser.Anchored = true
	laser.Parent = workspace.RayIgnore
	
	game:GetService("Debris"):AddItem(laser, 0.1)
end

And this is the client script, the thing that fires the event: Again, just a little piece.

function requestShot()
	registerShot:FireServer({tool:WaitForChild("FirePart"), mouse.Hit.Position, tool})
	requestAnimation("Recoil")
end

Any help is needed.

1 comment

0

When it's fired, Give the firepart CFrame first.

1 answer

✓ Accepted answer

When the event is fired, Give the CFrame information. Example:

Event:FireServer("thing lol idk", Mouse.idk, mouse.Hit.Position, YourPart.CFrame)

The thing that delays it that your ur internet bad jk. Because your character move based on your client. If it moves on the server it will delay too. Because it took some time to send something to the server.

2 comments

0

It's not my internet lol but I'll try it thx

0

lol xd

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