Weird gun bullet position

I’ve been working on my own gun system with @korbykobs and it works well, but there is one flaw with it. The bullets seem to appear late and don’t come from the front of the gun.

My guns:

Example guns:

Anyone know why this is happening? Thanks!

4 Likes

Can I see your scripts, I am guessing that the problem is that you move in time between when you fire the gun and when the server generates the beam, so the beam spawns where you used to be, not where you are currently.

1 Like

guncode.txt (1.6 KB)

Sorry for using a txt file, pastebin wouldn’t allow it for some reason. This is the code for the top gun, the bottom gun is just an example of what I want it to be like from CreepySins’ Area 47.

1 Like

I’m just going to format the code,

ammo = ammo - 1
script.Parent.Handle.Fired:Play()
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {script.Parent.Parent}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local raycast = game.Workspace:Raycast(script.Parent.Tip.Position, CFrame.new(script.Parent.Tip.Position, value1.Position).LookVector * 2000, raycastParams)
if raycast ~= nil then
	for i,v in pairs(game.Players:GetChildren()) do
		if raycast.Instance:IsDescendantOf(v.Character) == true then
			v.Character.Humanoid:TakeDamage(script.Parent.Stats.Damage.Value)
			script.Parent.Handle.Hit:Play()
			game.Players:GetPlayerFromCharacter(script.Parent.Parent).PlayerGui.GunCursorGui.Dot.Hit.Visible = true
			wait(0.05)
			game.Players:GetPlayerFromCharacter(script.Parent.Parent).PlayerGui.GunCursorGui.Dot.Hit.Visible = false
		end
	end
local visBullet = Instance.new("Part")
visBullet.Material = Enum.Material.Neon
visBullet.BrickColor = BrickColor.new("Cool yellow")
visBullet.Anchored = true
visBullet.CanCollide = false
local distance = (script.Parent.Tip.Position - raycast.Position).Magnitude
visBullet.CFrame = CFrame.new(script.Parent.Tip.Position, raycast.Position) * CFrame.new(0,0,-distance / 2)
visBullet.Size = Vector3.new(0.25,0.25,distance)
visBullet.Parent = game.Workspace
script.Parent.Tip.Flash.Transparency = NumberSequence.new(0,0)
wait(0.025)
visBullet.Size = Vector3.new(0.25,0.25,distance/2)
visBullet.CFrame = CFrame.new(raycast.Position, script.Parent.Tip.Position) * CFrame.new(0,0,-distance)
script.Parent.Tip.Flash.Transparency = NumberSequence.new(1,1)
visBullet:Destroy()

Thanks, I don’t know how to format correctly.

Maybe try removing this wait:_

Also to format your code, put 3 of these ` on the line infront of your code. It is the key above the “Tab” key. Like this without the quotation marks:
" --code here "

1 Like

Doesn’t affect it sadly. I’m not sure if the example game uses some other code to align the visual Bullet with some extra CFrame in the direction the character is moving, but I doubt this.

Edit: Thanks for telling me how to format

1 Like

I gotta go, I’ll look at this more when I get back. Sorry I couldn’t be of more help, good luck!

1 Like

Is this code localscript or normal script?

1 Like

Normal script. Would having the local script make the visual bullet make it smoother?

1 Like

Visuals should be done on the client, otherwise there will be noticeable latency from the server.

1 Like

How would I make the bullet appear on the server then? And if I make it visible on the server, how would I make the server bullet invisible on the client?

Yes, There is always a lag in sending remoteevent from the client to the server.

It looks like you are doing a raycast on the server.
If you do a raycast on the server, the player may no longer be there due to network latency.

I recommend reading this one:
https://developer.valvesoftware.com/wiki/Source_Multiplayer_Networking

But I think it’s tough to do this with Roblox.
To avoid this, you should send the player who hit and hit position in the remoteevent.
But this remoteevents value can be spoofed, so you must do basic exploit detection.

1 Like

I’ll try to implement that as a prototype to see how it works.

1 Like

Thanks to @LowPolys and @dollychun for helping out, I’ve managed to get the look I want!