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

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

Asked by 3 years ago
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

Log in to vote
0
Answered by
blazar04 281 Moderation Voter
3 years ago

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.

0
I am trying to place the part where you click put at a fixed distance. ChicaLower 25 — 3y
Ad

Answer this question