I have two weapons I've made & scripted using the same fashion for both. One works completely fine (M1911) & the other (Ak-47) doesn't work at all. Now I know its because of this one error that keeps popping up, "Handle is not a valid member of tool"? I have a handle inside of my tool exactly like my M1911 which works just fine. Now note my Ak did work at one point before I tried adding sound effects for, equip, reload, magazine in, & empty clip effects. Also note that I added the same effects with different audio for the M1911. The script below is my main code and mind you im getting an error for the handle under my variables where I define handle.
-- Variables local tool = script.Parent.Parent local hole = tool.barrel local handle = tool.Handle local canShoot = true local config = tool.Config local ammo = config.Ammo local maxammo = config.MaxAmmo local dmg = config.Damage local allowtrace = config.AllowTracing local clips = config.Clips local range = config.Range local plr = game:GetService("Players").LocalPlayer local cooldown = config.CoolDown local mouse = game.Players.LocalPlayer:GetMouse() local reloadtime = config.ReloadTime local isReloading = false --//Sounds local reload = tool.Handle.reloadAK local fire = tool.Handle.akfire local equip = tool.Handle.EquipSound local empty = tool.Handle.emptyclip local magin = tool.Handle.Magazinein -- Events tool.Equipped:Connect(function(mouse) equip:Play() -- Should play equip sound tool.Activated:Connect(function() if not isReloading then if ammo.Value > 0 then if canShoot then --Play Sound fire:Play() -- Should play Shooting Sound -- Doesnt Allow Spam canShoot = false -- Ray Get, & Set local ray = Ray.new(hole.CFrame.p, (mouse.hit.p - hole.CFrame.p) * range.Value) local hit, position = workspace:FindPartOnRay(ray, plr.Character, false, true) if allowtrace.Value == true then -- Make part local trace = Instance.new("Part", workspace) trace.Material = Enum.Material.Plastic trace.BrickColor = BrickColor.new("Really black") trace.CanCollide = false trace.Anchored = true trace.Locked = true trace.Transparency = 0.2 -- Show Direction local distance = (hole.CFrame.p - position).magnitude trace.Size = Vector3.new(0.22, 0.1, distance) trace.CFrame = CFrame.new(hole.CFrame.p, position) * CFrame.new(0, 0, -distance/2) -- Remove Debris game:GetService("Debris"):AddItem(trace, 0.1) end -- Hit Detection if hit then local humanoid = hit.Parent:FindFirstChild("Humanoid") if humanoid then -- Double Damage Headshots if hit.Name == "Head" then print("Headshot") humanoid:TakeDamage(dmg.Value*2) else -- Regular Damage bodyshots print("Bodyshot") humanoid:TakeDamage(dmg.Value) end end end ammo.Value = ammo.Value - 1 wait(cooldown) canShoot = true end else -- out of ammo empty:Play() end end end) -- Reload event mouse.KeyDown:Connect(function(key) key:lower() if key == "r" then if not isReloading then if clips.Value > 0 then reload:Play() -- Should Play Reload Sound isReloading = true ammo.Value = maxammo.Value clips.Value = clips.Value - 1 wait(reloadtime.Value) magin:Play() -- Should Play MagIn Sound isReloading = false end end end end) end)
Now ive gone through & placed notes where the sounds are called upon to play. Any other info to help me solve this I can also provide. Thanks for the help!
~GoodkidMad
The script was loading before the handle loaded, wait for the handle to load:
local handle = tool:WaitForChild("Handle")