I need help with fixing this bug in my code.
Server Script:
local gun = script.Parent.Parent
local getMouseRemote = game.ReplicatedStorage.GetMousePosition
gun.Activated:Connect(function()
local player = game.Players:FindFirstChild(gun.Parent.Name)
local rayOrigin = gun.Handle.rayOrigin.Position
local mousePosition = getMouseRemote:FireClient(player)
local directionToFire = (mousePosition - rayOrigin).Unit * 100
local raycastResult = workspace:Raycast(rayOrigin, directionToFire)
if raycastResult then
print(raycastResult.Instance)
print(raycastResult.Position)
print(raycastResult.Distance)
end
if raycastResult then
local humanoid = raycastResult.Instance.Parent:FindFirstChild("Humanoid")
local head = raycastResult.Instance:FindFirstChild("Head")
if head then
humanoid:TakeDamage(60)
else
humanoid:TakeDamge(25)
end
end
end)
Local Script (I put this inside the handle):
game.ReplicatedStorage.GetMousePosition.OnClientEvent:Connect(function()
return game.Players.LocalPlayer:GetMouse().Hit.Position
end)
The error I’m getting:
Workspace.Tool.Handle.ShootScript:11: attempt to perform arithmetic (sub) on nil and Vector3
I think it’s a problem relating to the remote event? Then again, still learning scripting so I could be wrong about that.
Any amount of help is appreciated.
Cheers!