Im making a GUI where If you press It a part will spawn below you but In this situation I want to make a GUI that spawns a part on the tool your holding (The tool I want the part spawn Is a sword name "Part" but It appears to not be working, this Is the code:
local Button = script.Parent
Button.MouseButton1Down:Connect(function(activate) local Part = Instance.new("Part") Part.Size = Vector3.new(2.33, 2.788, 2.519) Part.Position = Vector3.new(game.Workspace.Starterpack.part) Part.Parent = workspace Part.Anchored = true Part.BrickColor = BrickColor.new("Black") end)
Please use the lua code block formats. This should work:
01 | Button = script.Parent |
02 |
03 | Button.MouseButton 1 Down:Connect( function () |
04 | local Player = Button.Parent.Parent.Parent.Parent |
05 | local Character = Player.Character |
06 | local Part = Instance.new( "Part" ) |
07 | Part.Size = Vector 3. new( 2.33 , 2.788 , 2.519 ) |
08 | Part.Position = Vector 3. new(Character:FindFirstChildOfClass( "Tool" ).Handle.Position - Vector 3. new( 0 , 4 , 0 )) |
09 | Part.Parent = workspace |
10 | Part.Anchored = true |
11 | Part.BrickColor = BrickColor.new( "Black" ) |
12 | end ) |
I'm also assuming this is a serverscript, and the button is located inside of a frame which is inside of a ScreenGui. If it doesn't work, add me on Discord: Undaub#4107