Attempt to call a Vector3 value error

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?
    I have an error in the output in which I want to fix

  2. What is the issue? Include screenshots / videos if possible!
    When calling the mousePosition variable in the mouseRaycast function as when it tries to run, it returns an attempt to call a Vector3 value error in the output

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried removing the player variable but that results in another error which says Argument 1 missing or nil

Server Script

local function mouseRaycast(player, origin)
	local mousePosition = GetHitpoint:InvokeClient(player)
	print(player)
	
	local raycastParams = RaycastParams.new()
	raycastParams.FilterType = Enum.RaycastFilterType.Exclude
	raycastParams.FilterDescendantsInstances = {player.Character}
	
	local raycastResult = workspace:Raycast(origin, (mousePosition - origin) * 300, raycastParams)
	
	return raycastResult
end


local attackFunctions = {	
	["Firearm"] = function(player, weapon, config)
		local ammo = 8
		local maxAmmo = 8
		
		local raycastResult = mouseRaycast(player, weapon.Handle)
		
		if raycastResult then
			-- some extra code
		end
		
	end,
}

Client Script

local Players = game:GetService("Players")

local player = Players.LocalPlayer

local function mouse()
	local mouse = player:GetMouse()
	
	return mouse.Hit.Position
end

GetHitpoint.OnClientInvoke = mouse()

Remove the () from this line. The reason why this error is occuring is because you’re calling the function, and it’s passing the hit position to OnClientEvent because that’s what the function returns, which is the Vector3 value

Removing the () and only providing the function name passes the function instead of calling and running the code

2 Likes

^ Yup, what they said.

I’d like to add that it’s always good to learn about what things represent in code by using print.

So in this case, if you were to do print(mouse) on that line. The console would say:
“function: [hex value]”
indicating that is a function.

However, you can think of the parentheses in this case like an operator.
By putting the parentheses right after a function’s name, you are telling Lua that you want to call the function. And the result of the “function call operator” is the return value of the function.
In the OP’s case, the “mouse” function returns a Vector3 from “mouse.Hit.Position”.

This is how we distinguish between the function itself as an object, and the usage of the function.

This can also be shown with the code:
print( type( mouse ) )
print( type( mouse() ) )

thanks it worked, didnt expect a response this fast

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.