I have a perfectly working turret, however on the client side the bullets appear to be getting deleted early.
It looks fine on the server
I tried to just delete the bullet on the client side, but that didnt work. I also tried other methods of spawning bullets, but those methods dont give me the same results I want
This is the spawn bullet function:
local function fireBullet()
-- Create the bullet part
local bullet = Instance.new("Part")
bullet.Size = Vector3.new(0.2, 0.2, 3)
bullet.Shape = Enum.PartType.Block
bullet.Color = Color3.fromRGB(255, 255, 0)
bullet.Material = Enum.Material.SmoothPlastic
bullet.CFrame = fireBulletPart.CFrame
bullet.Anchored = false
bullet.CanCollide = false
bullet.Parent = workspace
-- Set the bullet's velocity (initial speed in the direction it's fired)
local velocity = fireBulletPart.CFrame.LookVector * BULLET_SPEED
bullet.Velocity = velocity
-- Detect collision with players or NPCs
bullet.Touched:Connect(function(hit)
if hit and hit.Parent and not hit:IsDescendantOf(script.Parent) then
local hitParent = hit.Parent
local humanoid = hitParent:FindFirstChild("Humanoid")
if humanoid then
humanoid:TakeDamage(1)
end
bullet:Destroy()
end
end)
Debris:AddItem(bullet, 5)
end