Problem with " Unable to assign property Value. Vector3 expected, got Instance"

Hello Devs!

I’m having a little problem with my scripting.
So i got an error output
" Unable to assign property Value. Vector3 expected, got Instance"

I’m trying to make Client > Server mouse position update function. But the problem seems to start when updating the value. Here is the code i use.


while true do
	local Player = game.Players.LocalPlayer
	local MousePosition = Player:GetMouse().Hit.p
	game.ReplicatedStorage.SendPlayerMousePosition:FireServer(Player.Character, MousePosition)


function UpdatePosition(Character, Position)
	Character.Character.CurrentMousePosition.Value = Position


EXPLORER TAB` (If needed)

Thank you for your support!

OnServerEvent puts the player the fired the event as the first parameter automatically, so change your UpdatePosition function

function UpdatePosition(Player, Character, Position)

No need to change anything in FireServer in this case. Only thing I would say is to remove your Player.Character and Character parameter as you can easily do Player.Character now

OnServerEvent passes a default argument which is the player that fired the event. Meaning right now, on the server, your variables are:

Character = Player
Position = Character

To fix this, add a player argument to your function:

function UpdatePosition(Player, Character, Position)
	Character.Character.CurrentMousePosition.Value = Position

Unrelated to your question, but I’d recommend using more variables. On the client side, your loop re-indexes objects that can be easily stored, but currently, they’re not, which wastes a lot of time.

I’d recommend changing it to something along the lines of:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local SendPlayerMousePositionEvent = ReplicatedStorage:WaitForChild("SendPlayerMousePosition")
local Mouse = LocalPlayer:GetMouse()

while true do
	local MousePosition = Mouse.Hit.p
    if LocalPlayer.Character then -- Probably no reason to send if the character doesn't exist yet.
	   SendPlayerMousePositionEvent:FireServer(LocalPlayer.Character, MousePosition)

Thanks for the help!

Your answer helped me a lot!

But since @Stratiz typed first (as i see myself) and have the longest answer. I will mark the solution for him / her

I also want to say thank you to @EmbatTheHybrid for the answer.
That’s all have a great day!

1 Like

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