Bullets only clone when the character move

  1. What do you want to achieve? So, I was trying to make gun. It was almost finished, and the gun scripted by me. I’m only having bullet cloning problems, it’s only clone when the character move and not clone the bullet when the character is standing.

  2. What is the issue?
    robloxapp-20230101-0732091.wmv (1.4 MB)
    You can see the bullet is not cloning when I was idling.

  3. What solutions have you tried so far? I tried everything.

Here’s some script that I made, Damaging Bullet :

-- Damaging bullet script
local bullet = script.Parent

bullet.Touched:Connect(function(hit)
	local damage = 18
	if hit then
		local human = hit.Parent:FindFirstChild("Humanoid")
		if human and human.Parent.Name ~= bullet.creator.Value then
			human:TakeDamage(damage)
			
		end
		bullet:Destroy()
	end
end)

If you can help I appreciated.

Also Happy New Year :smile:

1 Like

This bullet damaging script does not control bullet movement or clone the bullet. We need to see the other script to help you.

ok wait here’s Client Script

-- Tool --
local MP5 = script.Parent

-- In-tool variables --
local Handle = MP5:WaitForChild("Handle")
local ShootPart = MP5:WaitForChild("Shoot")
local ShootParticle = ShootPart:WaitForChild("ShootParticle")
local Settings = MP5:WaitForChild("Settings")

-- In-settings variavles --
local Ammo = Settings:WaitForChild("Ammo")

-- Automatic variables --
local Automode = Handle:WaitForChild("IsAutomatic")

-- UIs variables --
local GUI = script:WaitForChild("GUI")
local AmmoGUI = GUI:WaitForChild("AmmoGui")

-- Sound variables --
local ReloadSound = Handle:WaitForChild("ReloadSound")
local FireSound = Handle:WaitForChild("FireSound")
local EquipSound = Handle:WaitForChild("EquipSound")

-- Local's player variables --
local Mouse = game.Players.LocalPlayer:GetMouse()
local PlayerGui = game.Players.LocalPlayer.PlayerGui

-- Boolean variables --
local IsShooting = false
local IsReloading = false
local IsEquipping = false

-- Remotes variables --
local ShootServer = MP5:WaitForChild("Remotes")

-- Animation variables --
local HoldAnim = MP5.Animations:WaitForChild("Hold")

-- Other Name of Animation variables --
local HoldTrack

-- Make sure don't mess up these code or it might not work because of your mistakes, only edit, ONLY EDIT! I'M NOT GOING TO HELP YOU IF YOU MESS UP WITH IT --
function Equipping() -- Now it's equipping Func.
	local character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait() -- Get character
	
	AmmoGUI.Parent = PlayerGui
	AmmoGUI.Enabled = true -- Open he GUI
	AmmoGUI.Frame.WeaponName.Text = MP5.Name
	
	IsEquipping = true -- True
	
	
	Ammo:GetPropertyChangedSignal("Value"):Connect(function()
		AmmoGUI.Frame.Ammo.Text = Ammo.Value
	end)
	
	EquipSound:Play()
	-- Changing mouse icon :3 --
	Mouse.Icon = 'rbxassetid://11894826876'
	
-- It's time for animation! --
local humanoid = character:WaitForChild("Humanoid") -- Load Humanoid
	if humanoid then
	pcall(function()
		HoldTrack = humanoid:LoadAnimation(HoldAnim) -- Load Animation
		HoldTrack:Play() -- Play
		end)
	end
end

function Firing() -- What next? Oh it's shooting Func!
	
		FireSound:Play()
	
	ShootServer.ShootServer:FireServer(MP5.Handle.Position, Mouse.Hit.p) -- Let's send this to server script instead of writing on this
	
	ShootParticle.Enabled = true
	
		wait(0.1) -- This is for firerate uhhh..
	
	ShootParticle.Enabled = false 
	
	Ammo.Value = Ammo.Value - 1
	
	if Ammo.Value > 0 then return end
end

function UnEquipping() -- Finally, unequipping Func!
	AmmoGUI.Enabled = false
	IsShooting = false
	IsReloading = false
	IsEquipping = false
	
	-- Now, make mouse icon become default --
	Mouse.Icon = ''
	
	if HoldTrack then
		HoldTrack:Stop() -- Stop
	end
end

MP5.Activated:Connect(function()
	IsShooting = true -- True
	if Automode.Value == true then -- If automode enabled then
		repeat -- repeating the fire until the "IsShooting" turn into false
			wait(0.01)
			Firing() -- FIRE
		until not IsShooting
	else -- if not true then it fires just like semi gun
		wait(0.2)
		Firing() -- FIRE
	end
end)

Mouse.Button1Up:Connect(function()
		IsShooting = false -- It's false. don't be stupid
	end)
-- Event Listeners --
MP5.Equipped:Connect(Equipping)
MP5.Unequipped:Connect(UnEquipping)

ignore the ammo it was not finished

Server Script

local MP5 = script.Parent

local ShootServer = MP5:WaitForChild("Remotes")

local speed = 500

function Shooting(Player, GunPos, MousePos)
	
	local bullet = Instance.new("Part", game.Workspace.BulletContainer)
	bullet.Size = Vector3.new(0.2,0.2,0.2)
	bullet.Orientation = Vector3.new(0,90,0)
	bullet.BrickColor = BrickColor.new("Gold")
	bullet.CFrame = CFrame.new(GunPos,MousePos)
	bullet.CanCollide = false
	bullet.Name = "Bullet"
	
	local Damagescript = MP5:WaitForChild("DamagingBullet"):Clone()
	Damagescript.Parent = bullet
	Damagescript.Enabled = true
	
	local the_creator = Instance.new("StringValue")
	the_creator.Name = "creator"
	the_creator.Parent = bullet
	the_creator.Value = Player.Name
	
	local gravity = Instance.new("BodyVelocity", bullet)
	gravity.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
	gravity.Velocity = bullet.CFrame.LookVector * speed
	game:GetService("Debris"):AddItem(bullet, 5)
	
end

ShootServer.ShootServer.OnServerEvent:Connect(Shooting)
  1. Does the server script ever set the position of the bullet to be right outside of the gun barrel? I cannot see that. All I see is it changing the direction in which the bullet is facing.

No, I set the position of the bullet inside gun barrel.

Nvm i solved by myself, instead of writting in server script i decided to rewrite the bullet in client script and works fine im so stupid

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.