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

Why isn't mouse.hit working properly in this script?

I was making a script that spawns a part (Line 14) where ever the player clicks with the tool,but for some reason it spawns in the middle of the base plate ,why?

---------------Vairbles---------------
local Tool = script.Parent
local Handle = script.Parent.Handle
local Player = game.Players.LocalPlayer--Gets LocalPlayer(which is the player with tool or script)
local PlayersMouse = Player:GetMouse()--Gets the Players mouse with the GetMouse() method
----------------EquipedEvent-------------
    Tool.Equipped:connect(function(Mouse)
        ---------------------Button1Down---------------------------------
        Mouse.Button1Down:connect(function()--When the player press the right button(Button1) it will do the thing below
            Mouse.Icon  = "http://www.roblox.com/asset/?id=13890082"--Changes the crusor Icon to a plus sign
            Handle.BrickColor = BrickColor.new("Bright green")
            end)
            --------------------Button1Up---------------------------------
            Mouse.Button1Up:connect(function()--When the player releases the right button(Button1) it will do the thing below
                    local Part = Instance.new("Part",game.workspace)
                       	  Part.CFrame = CFrame.new(Part.Position,Mouse.Hit.p)
                Mouse.Icon = ""--Changes the crusor icon back to normal
                Handle.BrickColor = BrickColor.new ("Bright red")
                ------------------------------------------------------------
            end)
    end)

1 answer

✓ Accepted answer

Part.Position is initially Vector3.new(0,0,0), and that is where you are telling it to go on line 16.

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