So ive inserted a gun modeled from blender, put a handle part into the tool, and scripted with filtering enabled, yet when I try to equip the tool it simply does not show.
Note I also got a error:
Players.GoodkidMad.Backpack.m1911.Scripts.Main:25: attempt to index local 'mouse' (a nil value)
-- Variables local tool = script.Parent.Parent local hole = tool.barrel local handle = tool.Handle local debounce = 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 -- Events tool.Equipped:Connect(function(mouse) tool.Activated:Connect(function(mouse) if debounce then -- Doesnt Allow Spam debounce = false -- Ray Get, & Set mouse.Button1Down:connect(function() 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 humanoid:TakeDamage(dmg.Value*2) else -- Regular Damage bodyshots humanoid:TakeDamage(dmg.Value) end end end wait(cooldown) debounce = false end) end end) end)
Would greatly appreciate a response.
First things first - you have your button1down event which will create a new event on top of all the other times you equipped it. Your activated function will be fine instead since it fires every time a player clicks with the tool open.
I think your script is erroring saying mouse is nil because there are two mouse variables and the mouse variable that the script is referring to is the activated's mouse variable. Activated doesn't have a mouse parameter I think. Either way, you can get the mouse using Player:GetMouse() since this is a local script.
About your gun not showing, try without any scripts at all. Maybe it's not welded properly (if it's not a mesh in your handle this might be the case)
Turns out I needed to weld the guns parts, as far as the gun shooting (raycast) I had to change the debounce, to canShoot and change the true & false around. Also make sure when your using the (mouse) term you define!
local mouse = game.Players.LocalPlayer:GetMouse()
Full code look like this now:
-- 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() -- Events tool.Equipped:Connect(function(mouse) tool.Activated:Connect(function() if canShoot then -- 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 wait(cooldown) canShoot = true end end) end)