Can someone tell me how i can make it work?, i made this but it doesn't work
What i'm trying to do is if i click an object that object will be teleported to me
local Mouse = game.Players.LocalPlayer:GetMouse() Mouse.Button1Down:Connect(function() for i=1, 25 do wait(0) Mouse.Hit.Parent.Nap.CFrame = game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame*CFrame.new(0,0,-2.8) end)
The Hit
property of the mouse is a CFrame
value, not what the mouse is hovering over. The Target
property is what you're looking for. This property will hold the part the mouse is hovering over, nil
if no part is being hovered over, so you need to do checks to see if the target exists first.
local client = game:GetService("Players").LocalPlayer local Mouse = client:GetMouse() Mouse.Button1Down:Connect(function() local target = Mouse.Target for i=1, 25 do wait() if target and target.Parent:FindFirstChild("Nap") then target.Parent.Nap.CFrame = client.Character:GetPrimaryPartCFrame() * CFrame.new(0,0,-2.8) end end end)