Hello, I am working on a game in ROBLOX called Dreadfire. I am scripting the guns, but i've run into a problem..
So basically, this is a local script inside of the tool. Everything works in it except for the activated part. The only thing that works is the sound. and when I test it, I do not see a bullet firing out of the chamber. Any help?
I also had taken the script from the laser pistol ROBLOX created, but tried to modify it.
-----------------
--| Constants |--
-----------------
local SHOT_SPEED = 100
local SHOT_TIME = 1
local NOZZLE_OFFSET = Vector3.new(0, 0.4, -1.1)
-----------------
--| Variables |--
-----------------
local PlayersService = game:GetService('Players')
local DebrisService = game:GetService('Debris')
local Tool = script.Parent
local Handle = Tool:WaitForChild('Handle')
local FireSound = Handle:WaitForChild('Fire')
local ReloadSound = Handle:WaitForChild('Reload')
local Character = nil
local Humanoid = nil
local Player = nil
-----------------
--| Functions |--
-----------------
-- Returns a character ancestor and its Humanoid, or nil
local function FindCharacterAncestor(subject)
if subject and subject ~= workspace then
local humanoid = subject:FindFirstChild('Humanoid')
if humanoid then
return subject, humanoid
else
return FindCharacterAncestor(subject.Parent)
end
end
return nil
end
local function BaseShot()
local Burst = Instance.new('Part')
Burst.Name = "Burst"
BaseShot.FormFactor = Enum.FormFactor.Custom
BaseShot.Size = Vector3.new(0.2, 0.2, 3)
BaseShot.CanCollide = false
BaseShot.BrickColor = BrickColor.new("Electric blue")
BaseShot.Material = "Neon"
end
local function OnTouched(shot, otherPart)
if otherPart.Name == "Sensor" then
if otherPart.Parent.Parent.Parent.Name == "Green Vest" then
script.Parent.Points = script.Parent.Points + 25
end
end
end
local function OnEquipped()
Character = Tool.Parent
Humanoid = Character:WaitForChild('Humanoid')
Player = PlayersService:GetPlayerFromCharacter(Character)
end
local function OnActivated()
if Humanoid.Health > 0 then
Tool.Enabled = false
FireSound:Play()
local handleCFrame = Handle.CFrame
local firingPoint = handleCFrame.p + handleCFrame:vectorToWorldSpace(NOZZLE_OFFSET)
local shotCFrame = CFrame.new(firingPoint, Humanoid.TargetPoint)
local laserShotClone = BaseShot()
laserShotClone.CFrame = shotCFrame + (shotCFrame.lookVector * (BaseShot.Size.Z / 2))
local bodyVelocity = Instance.new('BodyVelocity')
bodyVelocity.velocity = shotCFrame.lookVector * SHOT_SPEED
bodyVelocity.Parent = laserShotClone
DebrisService:AddItem(laserShotClone, SHOT_TIME)
wait(0.6) -- FireSound length
ReloadSound:Play()
wait(0.75) -- ReloadSound length
Tool.Enabled = true
end
end
--------------------
--| Script Logic |--
--------------------
Tool.Equipped:connect(OnEquipped)
Tool.Activated:connect(OnActivated)

1 comment
I don't know, it wont show the bullet when I click, but it makes the firing sound