I been having a kinda big problem. So I made a laserbeam that shoots where ever you click, and obviously I used GetMouse. The main problem is is I can't get the mouse in the server script, here is what I am talking about. I made a Remote Event and passed mouse in it, then fired the event. But the local script is fine it does it job the main problem is in the server script, here is the code to show you want I am talking about.
local event = game.ReplicatedStorage.BeamEvent event.OnServerEvent:Connect(function(player,mouse) -- Sound local sound = Instance.new("Sound") sound.SoundId = "rbxassetid://1398471768" sound.Volume = 10 sound:Play() -- Beam local lazerbeam = Instance.new("Part", workspace) sound.Parent = lazerbeam lazerbeam.Anchored = true lazerbeam.CanCollide = false lazerbeam.Transparency = 0.5 lazerbeam.Material = Enum.Material.SmoothPlastic lazerbeam.Shape = "Cylinder" lazerbeam.Size = Vector3.new(1594.47, 7.68, 4.04) lazerbeam.Color = Color3.fromRGB(173,216,230) lazerbeam.Orientation = Vector3.new(0, 0, 90) lazerbeam.Position = mouse.Hit.Position lazerbeam.Touched:Connect(function(hit) hit.Parent:Destroy() hit.Parent.Humanoid.Health = 0 end) wait(3) lazerbeam:Destroy() end)
Now everything works great until it gets to the "lazerbeam.Position = mouse.Hit.Position" Also the error that it gives me is: 00:25:49.343 - ServerScriptService.Script:20: attempt to index nil with 'Hit'
If anyone can help me that would be great :D
When firing the event from the client you pass the whole thing not just the mouse so
event:FireServer(mouse.Hit.p) --then in the server you call it like so event.OnServerEvent:Connect(function(player, mousePosition) lazerbeam.Position = mousePosition end)