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.
CLIENT SCRIPT
while true do
local Player = game.Players.LocalPlayer
local MousePosition = Player:GetMouse().Hit.p
game.ReplicatedStorage.SendPlayerMousePosition:FireServer(Player.Character, MousePosition)
wait()
end
SERVER SCRIPT
function UpdatePosition(Character, Position)
Character.Character.CurrentMousePosition.Value = Position
end
game.ReplicatedStorage.SendPlayerMousePosition.OnServerEvent:Connect(UpdatePosition)
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
end
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)
end
task.wait()
end