im trying to make a gun on filtering enabled on, the remote event is in replicatedstorage. here's the script:
script.Parent.Parent.Activated:connect(function() game.ReplicatedStorage.GunShootingEvent:FireServer() end)
then here's the script for the main content
game.ReplicatedStorage.GunShootingEvent.OnServerEvent:connect(function(player) part = Instance.new("Part",game.Workspace) mouse = player:GetMouse() game.Debris:AddItem(part, 2) part.Size = Vector3.new(0.2,0.2,3) part.Material = "Neon" part.TopSurface = "Smooth" part.BottomSurface = "Smooth" part.LeftSurface = "Smooth" part.RightSurface = "Smooth" part.BrickColor = BrickColor.new("New Yeller") part.CanCollide = false part.CFrame = player.Character.StarterPistol.Handle.CFrame part.CFrame = CFrame.new(part.Position, mouse.Hit.p) v = Instance.new("BodyVelocity",part) v.Velocity = part.CFrame.lookVector * 500 v.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
end)
please I really need help on this, i put a variable stating the mouse, and I have no clue why it doesnt work.
GetMouse
can only be called on the client. If you need to get the Hit
of the mouse, pass it as a parameter, and when you call FireServer
from a client, pass the Hit
as an argument.local plr = game:GetService("Players").LocalPlayer local mouse = plr:GetMouse() script.Parent.Parent.Activated:Connect(function() -- connect is deprecated, use Connect game.ReplicatedStorage.GunShootingEvent:FireServer(mouse.Hit) -- sending Hit as arg end)
game.ReplicatedStorage.GunShootingEvent.OnServerEvent:Connect(function(player, hit) local part = Instance.new("Part") -- use more local variables, and the parent argument is deprecated and can cause performance issues part.Size = Vector3.new(0.2,0.2,3) part.Material = Enum.Material.Neon -- use enums part.BrickColor = BrickColor.new("New Yeller") part.CanCollide = false part.CFrame = CFrame.new(part.Position, hit.p) part.Parent = workspace -- always parent last game:GetService("Debris"):AddItem(part, 2) local v = Instance.new("BodyVelocity") v.Velocity = part.CFrame.lookVector * 500 v.MaxForce = Vector3.new(math.huge,math.huge,math.huge) v.Parent = part end)