Hello so I have this remote function that needs the players mouse, the arguments are:
Player, Tool, Handle, Gunshot, TracerPart, Mouse
My local script provides it with:
Tool, Handle, Handle.Gunshot, TracerPart, Mouse
However the Server script keeps outputting
ServerScriptService.GunSystem:53: Cannot find Mouse
Script
function cast(Player, Tool, Handle, Gunshot, TracerPart, Mouse)
local Cooldown = guncooldownlist[Tool.Name]
print(Cooldown)
local Damage = damagelist[Tool.Name]
print(Damage)
local Spread = spreadlist[Tool.Name]
print(Spread)
if Spread == nil or Damage == nil or Cooldown == nil then
error("Cannot find gun values")
end
if Mouse == nil then
error("Cannot find Mouse")
end
local ShootAtPart = Instance.new("Part")
ShootAtPart.CanCollide = false
ShootAtPart.Anchored = true
ShootAtPart.Transparency = 1
ShootAtPart.Size = Vector3.new(1,1,1)
ShootAtPart.Parent = workspace
local rng = math.random(1,2)
if rng == 1 then
ShootAtPart.CFrame = Mouse.Hit / math.random(0, Spread)
else
ShootAtPart.CFrame = Mouse.Hit * math.random(0, Spread)
end
local ray = Ray.new(TracerPart.CFrame.Position, (ShootAtPart.CFrame.Position - TracerPart.CFrame.Position).unit * 3000)
local part, position = workspace:FindPartOnRay(ray, Player.Character)
if part then
local human = part.Parent:FindFirstChild("Humanoid")
if not human then
human = part.Parent.Parent:FindFirstChild("Humanoid")
end
if human then
human:TakeDamage(Damage)
end
end
local light = Instance.new("PointLight")
light.Parent = Handle
light.Brightness = 12
local sparks = Sparks:Clone()
sparks.Parent = Handle
local smoke = Smoke:Clone()
smoke.Parent = ShootAtPart
smoke.Position = ShootAtPart.Position
spawn(function()
wait(0.7)
smoke.Hole.Enabled = false
end)
Debris:AddItem(light, 0.05)
Debris:AddItem(ShootAtPart, 1)
Debris:AddItem(smoke, 1.5)
end
HitCheck.OnServerInvoke = cast
Local Script
local UIS = game:GetService("UserInputService")
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local HitCheck = game:GetService("ReplicatedStorage"):WaitForChild("HitCheck")
local Mouse = Player:GetMouse()
local Handle = script.Parent
local Tool = Handle.Parent
local ScreenGui = Handle:WaitForChild("ScreenGui")
local TracerPart = Handle.Parent:WaitForChild("TracerPart")
local Ammo = Handle:WaitForChild("Ammo")
local Equipped = false
local Shooting = false
local Reloading = false
local cooldown = false
function GiveGUI()
GUI = ScreenGui:Clone()
GUI.Parent = Player.PlayerGui
end
function RemoveGui()
for i,v in pairs(Player.PlayerGui:GetChildren()) do
if v:IsA("ScreenGui") then
v:Destroy()
end
end
end
Handle.Parent.Equipped:Connect(function()
--print("Equipped")
Equipped = true
GiveGUI()
end)
Handle.Parent.Unequipped:Connect(function()
--print("UnEquipped")
Equipped = false
RemoveGui()
end)
UIS.InputBegan:Connect(function(input)
if Equipped == true and Reloading == false and Ammo.Value > 0 and cooldown == false then
if input.UserInputType == Enum.UserInputType.MouseButton1 then
--print("Mouse Down")
cooldown = true
Ammo.Value = Ammo.Value - 1
if Mouse == nil then
error("Client no mouse")
end
HitCheck:InvokeServer(Tool, Handle, Handle.Gunshot, TracerPart, Mouse)
GUI.CurrentAmmo.Text = Ammo.Value
ScreenGui.CurrentAmmo.Text = Ammo.Value
wait(0.2)
cooldown = false
end
end
end)
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.R and Equipped == true then
Reloading = true
wait(1)
if Equipped == true then
Ammo.Value = 12
GUI.CurrentAmmo.Text = Ammo.Value
ScreenGui.CurrentAmmo.Text = Ammo.Value
end
Reloading = false
end
end)