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

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

Asked by 10 years ago

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

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

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

Ad

Answer this question