I am editing a script for a simple gun (editing, because it is not mine), and it was working fine. The gun was shooting how I wanted it to. But after like three goes, and no edits, I started getting an output error from the client side and the gun stopped working. The error said
GunFire is not a valid member of Tool "Players.AbsurdAwesome101.Backpack.BasicGun" - Client - GunHandler:7
Like what??? Why?!?! Why the false hope? And why does it randomly stop working after like 3 tries? I don’t even know why I’m posting here, its not like big script guys can come and put a bandaid on it. Whatever, I have no idea, here’s code and images and stuff.
--client script
local tool = script.Parent
local origin = tool.Handle
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local laserFireEvent = script.Parent.GunFire
local laserFolder = workspace.Bullets
mouse.TargetFilter = laserFolder
local debounce = false
local cooldown = 0.1
tool.Activated:Connect(function()
if debounce then return end
debounce = true
local mousePosition = mouse.Hit.p
local originPosition = origin.Position
laserFireEvent:FireServer(mousePosition, originPosition)
wait(cooldown)
debounce = false
end)
Oh wait, here’s more
--server
local laserFireEvent = script.Parent.GunFire
local laserFolder = workspace.Bullets
local debris = game:GetService("Debris")
local range = 50
local function CreateBeam(origin, direction)
local midpoint = origin + direction/2
local part = Instance.new("Part")
part.Parent = laserFolder
part.Anchored = true
part.CanCollide = false
part.Material = Enum.Material.Neon
part.BrickColor = BrickColor.new("Institutional white")
part.CFrame = CFrame.new(midpoint, origin)
part.Size = Vector3.new(.25, .25, direction.magnitude)
debris:AddItem(part, 0.1)
end
laserFireEvent.OnServerEvent:Connect(function(player, mousePos, originPos)
local direction = (mousePos - originPos).Unit * range
local result = workspace:Raycast(originPos, direction)
if result then
local character = result.Instance.Parent
local humanoid = character:FindFirstChild("Humanoid")
if humanoid and not game.Players:FindFirstChild(character.Name) then
humanoid:TakeDamage(100)
local char = script.Parent.Parent
local person = game.Players:FindFirstChild(char.Name)
person.leaderstats.Kills.Value = person.leaderstats.Kills.Value + 1
end
end
CreateBeam(originPos, direction)
end)
And image for proof?? heck yea
Please help
