Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make a part where the player clicks within a certain range?

Asked by 4 years ago
Edited 4 years ago

Trying to make a range limit on how far something can be placed. This returns 'CFrame expected, got Vector3.' - 12

local part = game.ReplicatedStorage.Part
local uis = game:GetService("UserInputService")
local char = script.Parent
local m = game.Players.LocalPlayer:GetMouse()


uis.InputBegan:Connect(function(input,process)
    if not process and input.UserInputType == Enum.UserInputType.MouseButton1 then
        local ray = Ray.new(char.HumanoidRootPart.Position,(char.HumanoidRootPart.CFrame.p - m.hit.p).unit * -200)
        local clone = part:Clone()
        clone.Parent = workspace
        clone.CFrame = ray.Direction.unit *200
    end
end)
0
ray.Direction.unit is a Vector3 value. Multiplying it by 200 results in another Vector3 value. clone.CFrame needs to be a CFrame value. CFrame values are position with direction, but you're only providing position. fredfishy 833 — 4y
0
Instead do `clone.CFrame = CFrame.new(char.HumanoidRootPart.Position + m.hit.p) / 2, m.hit.p)` to get a CFrame with a position half way between the character and mouse, pointing toward the mouse. fredfishy 833 — 4y

Answer this question