I don’t know what’s going on, but all I"m trying to do is make particles (located in my ViewModel) Emit()
when I shoot. I’ve tried everything I can think of. Please HELP!
My local Script:
local TweenService = game:GetService("TweenService")
local Tool = script.Parent
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid")
local HeadshotUI = Player.PlayerGui:WaitForChild("HeadShot"):WaitForChild("Frame").HeadShot
local mouse = Player:GetMouse()
local HeadShotRemote = game:GetService("ReplicatedStorage").HeadShotRemote
local playerName = Player.Name
local ShootAnimation = Tool.Shoot
local ViewModel = Character:FindFirstChild("FlintlockPistol")
local AnimationController = ViewModel:FindFirstChildOfClass("AnimationController")
local animator = AnimationController:FindFirstChildOfClass("Animator")
-- Load the idle animation
local animationTrack = animator:LoadAnimation(ShootAnimation)
--[ SETTINGS ]
local ShootCooldown = 0.65
--[ GUN ATTRIBUTES ]
local Pew = Tool.Handle.Pew
local MetalRicochet = Tool.Handle.MetalRicochetSounds
local StoneRicochet = Tool.Handle.StoneRicochetSounds
local Reload = Tool.Handle.Reload
--[ FUNCTIONS ]
local function CreateBulletClient(player, ExactMousePosition)
local gunPosition = ViewModel.BulletStartPOS.Position -- Adjust this if needed
-- Create the beam part
local beam = Instance.new("Part")
beam.Name = "Bullet"
beam.Size = Vector3.new(0.1, 0.1, (gunPosition - ExactMousePosition).magnitude) -- Set initial size
beam.Color = Color3.fromRGB(255, 191, 0) -- Change color as needed
beam.Material = Enum.Material.Neon
beam.CanCollide = false
beam.CastShadow = false
beam.Anchored = true
beam.Parent = workspace
-- Set position and orientation
beam.CFrame = CFrame.new((gunPosition + ExactMousePosition) / 2, ExactMousePosition)
print(player.Name .. "'s bullet was created.")
-- Shrink the beam on both the X and Y axes over time (faster)
coroutine.wrap(function()
for i = 1, 10 do -- Reduced iterations for faster shrinking
-- Gradually decrease the X and Y dimensions to make the beam skinnier
local newSizeX = 0.1 * (1 - i / 10) -- Shrink the X size faster
local newSizeY = 0.1 * (1 - i / 10) -- Shrink the Y size faster
beam.Size = Vector3.new(newSizeX, newSizeY, beam.Size.Z) -- Keep Z (length) the same
wait(0.02) -- Reduced wait time for faster shrinking
end
beam:Destroy() -- Destroy the beam after it has finished shrinking
end)()
end
--[ MAIN CODE ]
local CanShoot = true
Tool.Activated:Connect(function()
if not CanShoot then return end
if Humanoid.Health == 0 then return end
if Tool.Enabled == false then return end
if Tool.Parent == Character then
local target = mouse.Target
if target and target:IsA("Part") or target:IsA("MeshPart") or target:IsA("UnionOperation") or target:IsA("Terrain") then
print(Player.Name .. " clicked their mouse.")
CanShoot = false
-- Play the Shoot animation
animationTrack:Play()
local ViewModel = Character:FindFirstChild("FlintlockPistol")
---------------------------------------------------------------------
--THIS IS WHERE THE EMITTION IS LOCATED!
local ShootFX1 = ViewModel:WaitForChild("Handle").MuzzleFlashHolder.ShootFX1:Emit(1)
local Sparks = ViewModel:WaitForChild("Handle").MuzzleFlashHolder.Sparks:Emit(1)
local Smoke = ViewModel:WaitForChild("Handle").MuzzleFlashHolder.Smoke
local Smoke1 = ViewModel:WaitForChild("Handle").MuzzleFlashHolder.Smoke1:Emit(2)
local Smoke2 = ViewModel:WaitForChild("Handle").MuzzleFlashHolder.Smoke2:Emit(4)
local ShootFX2 = ViewModel:WaitForChild("Handle").MuzzleFlashHolder.ShootFX2:Emit(1)
Smoke.Enabled = true
--ShootFX1:Emit(1)
--Sparks:Emit(1)
--Smoke1:Emit(2)
--Smoke2:Emit(4)
--ShootFX2:Emit(1)
---------------------------------------------------------------------
local humanoid = target.Parent:FindFirstChildOfClass("Humanoid")
local Head = target.Name == "Head"
local HeadShottedName = target.Parent.Name
local Terrain = target:IsA("Terrain")
local ExactMousePosition = mouse.Hit.Position
--print(Player.Name .. " shot: " .. target.Name .. ", which is inside of: " .. target.Parent.Name .. ".")
CreateBulletClient(Player, ExactMousePosition)
local remote = Tool:WaitForChild("DamageRemote")
remote:FireServer(humanoid, Head, Terrain, Pew, MetalRicochet, StoneRicochet, Reload, target, ExactMousePosition)
if Head then
HeadShotRemote:FireServer(nil, target) -- We don't need to pass HeadshotUI anymore
end
-- Wait for cooldown
wait(ShootCooldown)
CanShoot = true
else
print(Player.Name .. " shot: Void" )
end
else
print("Tool isn't equipped!!!")
end
end)
Tool.Equipped:Connect(function()
end)
Tool.Unequipped:Connect(function()
end)
-- Add this new part at the end of your LocalScript
HeadShotRemote.OnClientEvent:Connect(function(HeadshotMessage)
local HeadshotUIClone = HeadshotUI:Clone()
HeadshotUIClone.Parent = Player.PlayerGui:WaitForChild("HeadShot"):WaitForChild("Frame")
HeadshotUIClone.Visible = true
HeadshotUIClone.Text = HeadshotMessage
-- Destroy the UI after 5 seconds
wait(5)
HeadshotUIClone:Destroy()
end)