Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I get the player mouse position, then put a part there?

how do i do that

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local k = Instance.new("Part")

Mouse.Button1Down:Connect(function()
	k.Parent = game.Workspace
	k.Color = Color3.fromRGB(1,1,1)
	k.Size = Vector3.new(0.08, 0.08, 0.08)
	k.Anchored = true
	k.Position = Mouse.Position
	script.Parent.Shot.Value = true
	wait(.001)
	script.Parent.Shot.Value = false
end)

--//ClearUp\\--
while true do
if script.Parent.Shot.Value == true then
wait(math.random(1,5))
k:Destroy()
end
end

1 answer

✓ Accepted answer

You can use the Mouse.Hit position for this;

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local k = Instance.new("Part")

Mouse.Button1Down:Connect(function()
    k.Parent = game.Workspace
    k.Color = Color3.fromRGB(1,1,1)
    k.Size = Vector3.new(0.08, 0.08, 0.08)
    k.Anchored = true
    k.Position = Mouse.Hit
    -- If the above does not work, remove the -- before the following line and remove the line above.
    --k.CFrame = Mouse.Hit
    script.Parent.Shot.Value = true
    wait(.001)
    script.Parent.Shot.Value = false
end)

--//ClearUp\\--
while true do
	if script.Parent.Shot.Value == true then
		wait(math.random(1,5))
		k:Destroy()
	end
end

Note that this will only calculate parts that have CanCollide to true.

This discussion is preserved as it was. New answers, comments, and votes are closed.