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

How do I fix this bug, it works for a bit then stop? only works sometimes

local p = game.Players.LocalPlayer
local m = p:GetMouse()

m.Button1Down:Connect(function()
	local p = Instance.new("Part")
	p.CFrame = CFrame.new(game.Players.LocalPlayer.Character.Head.CFrame * m.Hit.LookVector*2)
	p.Parent = workspace
end)

When I click, it places itself correctly for a bit, after walking around a little bit, it suddenly spawns at random positions. How would I fix this?

1 answer

From what it looks like, you are trying to place the part where you click. All you have to do is set the parts position to mouse.Hit.p

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local mouse = player:GetMouse()

mouse.Button1Down:Connect(function()
    local part = Instance.new("Part")
    part.Position = mouse.Hit.p
    part.Parent = workspace
end)

It is also good practice to use more descriptive variable names.

1 comment

0

I am trying to place the part where you click put at a fixed distance.

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