im making my first gun so my code isnt the best, but how can i prevent the gun from shooting after the player unequipped it?
Client Side Code
local player = game.Players.LocalPlayer local mouse = player:GetMouse() script.Parent.Parent.Equipped:Connect(function(eqp) print("eqp") mouse.Button1Down:Connect(function(input) script.Parent.Parent.fire:FireServer(mouse.hit.p) end) end)
Server Side Code
local RS = game:GetService("ReplicatedStorage") local beam = RS.beam local tip = script.Parent script.Parent.Parent.fire.OnServerEvent:Connect(function(player, mousePos) print("hello") local beamClone = beam:Clone() beamClone.Parent = game.Workspace beamClone.Position = mousePos beamClone.CanCollide = false beamClone.Size = Vector3.new(.3,.3,.3) beamClone.BrickColor = BrickColor.new("New Yeller") beamClone.Material = "Neon" wait() beamClone:Destroy() end) --end)
I dont have any errors it works as id like it to but when i put the tool away it still fires the bullets when i click ANY advice would be helpful even if it doesn't have to do with the question, thanks!!
Use tool.Activated instead of mouse.Button1Down. Your client side code should be changed to this:
local mouse = game.Players.LocalPlayer:GetMouse() script.Parent.Parent.Activated:Connect(function() script.Parent.Parent.fire:FireServer(mouse.hit.p) end)
You can replace your original code with this and I'm sure that it will pretty much fix your problem.