I am trying to make a simple hit scan gun but I have this error
attempt to perform arithmetic (mul) on Vector3 and Instance
I dont know why this is happening as both Camera.Position and Hit.Position are both Vector3
here are the client and server scripts
Client
local GunSystem = script.Parent
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local ShotEvent = GunSystem:WaitForChild("FireGun")
GunSystem.Activated:Connect(function()
local Mouse = player:GetMouse()
local Camera = game.Workspace.CurrentCamera
local TargetPosition = Mouse.Hit.Position
local StartPosition = Camera.CFrame.Position
print(TargetPosition,StartPosition)
ShotEvent:FireServer(StartPosition, TargetPosition)
end)
Server
script.Parent.FireGun.OnServerEvent:Connect(function(player, StartPosition, TargetPosition)
local character = player.Character
if not character then return end
local rayDirection = (TargetPosition - StartPosition).unit * script.Parent.MaxDistance -- Error "attempt to perform arithmetic (mul) on Vector3 and Instance"
-- raycast camera to target
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {character} -- Ignore character
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
local raycastResult = workspace:Raycast(StartPosition, rayDirection, raycastParams)
if raycastResult then
print(raycastResult.Instance.Name)
local humanoid = raycastResult.Instance.Parent:FindFirstChild("Humanoid")
if humanoid then
humanoid:TakeDamage(script.Parent.Damage) -- Damage hit humanoid
end
end
end)
I’m not completely sure what this error means so if anyone can help It would be greatly appreciated