So i am making a tool where you can place bricks, but they wont place and won't even show me an error. Here is the script.
local mouse = game.Players.LocalPlayer:GetMouse() local Tool = script.Parent local location = mouse.Hit Tool.Equipped:connect(function(Mouse) Mouse.Button1Down:connect(function() local part = Instance.new('Part') part.Parent = workspace part.Anchored = true part.CFrame = location end) Mouse.Button1Up:connect(function() wait(30) game.Workspace.Part:remove() end) end)
Why did you define a mouse if you weren't going to use it in the first place? lol First issue is that the Mouse argument is a newly created Mouse object that isn't the player's mouse. It exists, so it won't error, but the functions won't run. Your second issue is that Mouse.Hit is a CFrame value, but it won't return the CFrame's Vector value.
Here's your code:
local mouse = game.Players.LocalPlayer:GetMouse() local Tool = script.Parent local location = mouse.Hit Tool.Equipped:connect(function(Mouse) Mouse.Button1Down:connect(function() local part = Instance.new('Part') part.Parent = workspace part.Anchored = true part.CFrame = location end) Mouse.Button1Up:connect(function() wait(30) game.Workspace.Part:remove() end) end)
Here's your code, but with some fixes:
local mouse = game.Players.LocalPlayer:GetMouse() local Tool = script.Parent Tool.Equipped:connect(function() mouse.Button1Down:connect(function() local location = mouse.Hit.p local part = Instance.new('Part') part.Parent = workspace part.Anchored = true part.Position = location end) mouse.Button1Up:connect(function() wait(30) game.Workspace.Part:remove() end) end)
If this helped you, don't forget to accept the answer :D
I get that you want the part to remove after 30 seconds here is better way to do this:
Your way:
local mouse = game.Players.LocalPlayer:GetMouse() local Tool = script.Parent Tool.Equipped:connect(function() mouse.Button1Down:connect(function() local location = mouse.Hit.p local part = Instance.new('Part') part.Parent = workspace part.Anchored = true part.Position = location end) mouse.Button1Up:connect(function() wait(30) game.Workspace.Part:remove() end) end)
My way:
local mouse = game.Players.LocalPlayer:GetMouse() local Tool = script.Parent Tool.Equipped:connect(function() mouse.Button1Down:connect(function() local location = mouse.Hit.p local part = Instance.new('Part') part.Parent = workspace part.Anchored = true part.Position = location game:GetService('Debris'):AddItem(part,30) end) end)