I am trying to make a script where when you click a player, they fly to you (not teleport), right now, it is a tool with a local script that when you click a person, it sends over the Mouse.Hit and Mouse.Target to a server script, but I keep getting the error Hit is not a valid member of CFrame. Here are the scripts.
Local script
local Tool = script.Parent local Player = game.Players.LocalPlayer local Cooldown = false local CDTime = 5 local Mouse = Player:GetMouse() Tool.Activated:Connect(function() if Cooldown then return end if Mouse.Target == nil then return end print(Mouse.Target) spawn(function() Cooldown = true wait(CDTime) Cooldown = false end) Tool.RemoteEvent:FireServer(Mouse.Hit, Mouse.Target) end)
Server Script
local Tool = script.Parent local Cooldown = false local CDTime = 10 Tool.RemoteEvent.OnServerEvent:Connect(function(Player, Mouse) if Cooldown then return end local char = Player.Character local root = Player.Character.HumanoidRootPart spawn(function() Cooldown = true wait(CDTime) Cooldown = false end) local bp = Instance.new("BodyPosition") bp.Position = root.Position bp.MaxForce = Vector3.new(1e9,1e9,1e9) bp.Parent = Mouse.Hit.Parent game.Debris:AddItem(bp,2) end)
On line 21 of your script you are accessing Mouse.Hit. Mouse is a parameter from your RemoteEvent, but in your LocalScript we see that it isn't being passed the mouse, it's being passed Mouse.Hit. So essentially, you are setting bp.Parent to Mouse.Hit.Hit! Mouse.Hit is a CFrame, so it gives you the error "Hit is not a valid member of CFrame". Also, remember that Mouse.Target is the part that the mouse is pointing to, and Mouse.Hit is the location of the mouse's cursor. The BodyPosition should be parented to the target, not the hit.