My gun bullets are not accurate and don’t go instantly
Don’t mind the quality
Here is a sample video:
My gun bullets are not accurate and don’t go instantly
Don’t mind the quality
Here is a sample video:
I think you’re supposed to provide your code so people can actually help you out. Video is optional, code is not.
I’m not a good scripter, sorry about that. The gun uses “ray” based on a simple system
Here is the weapon’s server code.
local maxammo = script.Parent.MaxAmmo.Value
local ammo = game.StarterGui.Ammo
local reloading = false
local spread = script.Parent.EDIT.Spread.Value
script.Parent.Shoot.OnServerEvent:Connect(function (plr,Target)
if plr.Character ~= nil and plr.Character.Humanoid.Health >= .1 and script.Parent.Enabled == true and reloading == false then
script.Parent.Enabled = false
local hit = false
if ammo.Value >= 1 then
ammo.Value = ammo.Value - 1
script.Parent.Handle.FireSound.PlaybackSpeed = math.random(90,110)/100
script.Parent.Handle.FireSound:Play()
for i = 1, script.Parent.EDIT.BulletsPerShot.Value do
local dist = (script.Parent.RPart.Position - Target).Magnitude
local ray = Ray.new(script.Parent.RPart.CFrame.p, (Target - script.Parent.RPart.CFrame.p + (Vector3.new(math.random(-spread,spread)/1000,math.random(-spread,spread)/1000,math.random(-spread,spread)/1000) * dist)).unit * 2000)
local part, position = workspace:FindPartOnRay(ray, plr.Character, false, true)
local beam = Instance.new("Part")
beam.Anchored = true
beam.CanCollide = false
beam.Material = "Neon"
if dist >= 60 then
beam.Size = Vector3.new(.05,.05,60)
else
beam.Size = Vector3.new(.05,.05,dist)
end
beam.CFrame = CFrame.new(script.Parent.RPart.CFrame.p, position) * CFrame.new(0,0,-beam.Size.Z/2)
game.Debris:AddItem(beam,10)
local fx = script.Parent.FX:Clone()
fx.Dist.Value = dist
fx.Parent = beam
fx.Disabled = false
beam.Parent = plr.Character
script.Parent.RPart.FlashGui.Label.Rotation = math.random(1, 360)
script.Parent.RPart.FlashGui.Enabled = true
script.Parent.RPart.Flash.Enabled = true
if part ~= nil then
local humanoid = part.Parent:FindFirstChild("Humanoid")
local hitPartName = part.Name
if part.Parent:FindFirstChild("Humanoid") and hitPartName == "Head" then
part.Parent:FindFirstChild("Humanoid"):TakeDamage(100)
local hitsound = script.Parent.Handle.Hit:Clone()
hitsound.Parent = part.Parent.HumanoidRootPart
game.Debris:AddItem(hitsound,2)
hitsound:Play()
hit = true
local blood = script.Parent.EDIT.Blood:Clone()
blood.Parent = part
blood.Enabled = true
game.Debris:AddItem(blood,.2)
elseif part.Parent:FindFirstChild("Humanoid") then
part.Parent:FindFirstChild("Humanoid"):TakeDamage(script.Parent.EDIT.Damage.Value)
local hitsound = script.Parent.Handle.Hit:Clone()
hitsound.Parent = part.Parent.HumanoidRootPart
game.Debris:AddItem(hitsound,2)
hitsound:Play()
hit = true
local blood = script.Parent.EDIT.Blood:Clone()
blood.Parent = part
blood.Enabled = true
game.Debris:AddItem(blood,.2)
else
print("Hum yok bro")
end
end
local hole = Instance.new("Part")
hole.Size = Vector3.new(.2,.2,.2)
hole.Material = "Mud"
hole.Anchored = true
hole.BrickColor = BrickColor.new("Brown")
hole.Shape = Enum.PartType.Cylinder
hole.CanCollide = false
hole.Position = position
hole.Transparency = 0.2
hole.Orientation = Vector3.new(0,0,-90)
hole.Transparency= 1
--Burada beam
local beam2 = Instance.new("Beam")
beam2.Color = ColorSequence.new(Color3.new(1, 0.666667, 0))
beam2.FaceCamera = true
beam2.Enabled = true
beam2.TextureLength = 1
beam2.LightEmission = 1
beam2.LightInfluence = 1
beam2.Texture = "rbxassetid://1274380363"
beam2.TextureLength = 1
beam2.TextureSpeed = 1000
beam2.CurveSize0 = 0
beam2.CurveSize1 = 0
beam2.Segments = 100
beam2.Width0 = 0.5
beam2.Width1 = 0.1
local attachment0 = Instance.new("Attachment")
local attachment1 = Instance.new("Attachment")
beam2.Attachment0 = attachment0
beam2.Attachment1 = attachment1
beam2.Parent = workspace
attachment0.Parent = hole
attachment1.Parent = script.Parent.RPart
game.Debris:AddItem(beam2,0.04)
local explosion = game.ReplicatedStorage.Explosion
local explosionClone = explosion:Clone()
explosionClone.Parent = game.Workspace
explosionClone.Position = hole.Position
game.Debris:AddItem(explosionClone,0.09)
local dust = script.Parent.EDIT.Dust:Clone()
dust.Parent = hole
dust.Enabled = true
dust.Script.Disabled = false
game.Debris:AddItem(hole, 1)
if hit == false then
hole.Parent = workspace
end
end
local shell = Instance.new("Part")
shell.Size = Vector3.new(.5,.5,.1)
shell.Position = script.Parent.ShellPart.Position
shell.Orientation = script.Parent.ShellPart.Orientation
shell.CanCollide = false
local shellmesh = Instance.new("SpecialMesh",shell)
shellmesh.MeshId = "rbxassetid://94295100"
shellmesh.TextureId = "rbxassetid://94287792"
shellmesh.Scale = Vector3.new(3,3,1)
game.Debris:AddItem(shell,5)
local v = script.Parent.ShellPart.CFrame:vectorToWorldSpace(Vector3.new(2 + math.random(4,14),math.random(-2,2),math.random(-2,2)))
shell.Velocity = v
shell.RotVelocity = Vector3.new(math.random(-25,25)/12,math.random(-25,25)/12,math.random(-25,25)/12)
shell.Parent = plr.Character
script.Parent.RPart.FlashGui.Enabled = false
script.Parent.RPart.Flash.Enabled = false
elseif ammo.Value <= 0 then
script.Parent.Handle.NoAmmo:Play()
end
wait(script.Parent.EDIT.Firerate.Value)
script.Parent.Enabled = true
end
end)
script.Parent.Reload.OnServerEvent:Connect(function ()
if reloading == false then
reloading = true
script.Parent.Handle.Reload:Play()
wait(script.Parent.EDIT.ReloadTime.Value)
ammo.Value = maxammo
reloading = false
end
end)
I think you just need to edit the spread value if you want more accurate shots.
I’ve already tried this. Something changed?
Yes it’s better but still not accurate.
Chances are because youre using an event fired from the client, there’s some latency for when this event is picked up from the server to when the bullet is made visible, my guess would be that your sending the correct information about where the bullet should hit, but because there is latency, and you have already moved on the client, the bullet appears to be hitting the position you clicked before moving.
when ive done my own projectile scripts, i tend to do the projectile calculation on both the client and server, show the projectile visuals of the bullet and where it hits on the client as this is more accurate to what the client sees, then check it against the server to see if the bullet hit position provided by the client is within a certain tolerance of where it hit on the server. If its within tolerence, register the shot.
This way the feedback to the client is instant, where they click is where the shot lands along with sounds and hitmarkers etc.
Ive not done many projectile scripts and the ones i did were a while ago but i remember having this same problem and this is what i did. Hope this helps.
I’ll take into account what you said, thanks for your help.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.