So I am trying to make a gun system, and I am working on the firing part now. The problem is that the gun is having problems when I try to create the ray. My script looks like:
function LaserFunctions.DrawLaser(plr, mouse)
local accuracy = Settings.Accuracy
local maxfiredistance = Settings.MaxDistance
local Ignore = plr.Character
local ray = Ray.new(tool.FirePart.CFrame.p,(mouse.Position - tool.FirePart.CFrame.p + Vector3.new(math.random(-accuracy,accuracy),math.random(-accuracy,accuracy),math.random(-accuracy,accuracy))).unit * maxfiredistance)
local part, position = workspace:FindPartOnRay(ray, Ignore, false, true)
local human
if part then
if part.Parent then
local human = part.Parent:FindFirstChild("Humanoid")
if not human then
human = part.Parent.Parent:FindFirstChild("Humanoid")
end
if human then
human = human
end
end
end
return ray, human, position
end
The code that calls that:
function GunFunctions.Fire(plr, mouse)
if currentammo > 0 then
local ray, touchedhuman, position = LaserFunctions:DrawLaser(plr, mouse)
else
if Settings.AutoReload == true then
GunFunctions.Reload(plr)
end
end
end
GunFunctions.Fire is called by a serversided script with the arguments of plr, mouse.Hit. Whenever I do this script, the output errors and says that “Position is not a member of Player” When I tried to switch the player and mouse variables around, it said that “Expected Vector3, got nil.” When I printed mouse.Position and plr in the GunFunctions.Fire, it printed the mouse position and the plr name. When I tried printing it in the DrawLaser function, it printed table for plr and the plr name for mouse. This is very confusing, and any help is appreciated.