#Updating mouse/part from server to client and client to server
1 messages · Page 1 of 1 (latest)
local function createMouseTrackerPart(player, character)
local userId = player.UserId
-- Clean up existing tracker
if mouseTrackerParts[userId] then
mouseTrackerParts[userId]:Destroy()
mouseTrackerParts[userId] = nil
end
local hrp = character:FindFirstChild("HumanoidRootPart")
if not hrp then return nil end
-- Create the tracker part
local trackerPart = Instance.new("Part")
trackerPart.Name = "MouseTracker_" .. player.Name
trackerPart.Size = Vector3.new(2, 2, 2)
trackerPart.Transparency = 0.5 -- Make it semi-visible for debugging
trackerPart.Color = Color3.fromRGB(255, 0, 0) -- Set color on server
trackerPart.Material = Enum.Material.Neon
trackerPart.CanCollide = false
trackerPart.Anchored = false
trackerPart.CFrame = hrp.CFrame * CFrame.new(0, 0, -3)
trackerPart.Parent = workspace.Effects
-- Set network ownership to the client and WAIT for it to complete
local success, err = pcall(function()
trackerPart:SetNetworkOwner(player)
end)
if not success then
warn("Failed to set network owner:", err)
trackerPart:Destroy()
return nil
end
-- Small delay to ensure network ownership transfer completes
task.wait(0.1)
-- Verify ownership transfer
local owner = nil
pcall(function()
owner = trackerPart:GetNetworkOwner()
end)
print(trackerPart.Position)
print(character.HumanoidRootPart.Position)
print("Network owner:", owner)
if owner ~= player then
warn("Network ownership not properly transferred! Owner:", owner)
else
print("Network ownership successfully transferred to:", player.Name)
end
-- Store reference
mouseTrackerParts[userId] = trackerPart
print("Server: Created mouse tracker part for", player.Name)
return trackerPart
end