How would I make a paint tool useful on only one base?
So I'm trying to edit a paint tool so it only works on the base that the player has selected to use. How Would I do this? Here's the script:
001 | local Tool = script.Parent |
004 | local origTexture = Tool.TextureId |
007 | function onButton 1 Down(mouse) |
024 | local inPalette = false |
026 | local selectedButtonTable = { } |
028 | function onMouseLeave(hoverSelection) |
029 | if oldButton ~ = nil then |
030 | local notSelected = true |
031 | local selectionText = "" |
032 | for key, value in pairs (selectedButtonTable) do |
033 | if oldButton = = value then |
036 | selectionText = value.BackgroundColor.Name |
040 | hoverSelection.Text = selectionText |
041 | oldButton.Parent.BackgroundColor = BrickColor.Black() |
047 | function onMouseEnter(hoverSelection, guiButton) |
048 | onMouseLeave(hoverSelection) |
049 | hoverSelection.Text = guiButton.BackgroundColor.Name |
050 | if guiButton ~ = selectedButton then |
051 | guiButton.Parent.BackgroundColor = BrickColor.White() |
052 | oldButton = guiButton |
056 | function onMouseUp(colorHolder, paletteFrame, guiButton) |
057 | if selectedButtonTable [ colorHolder ] ~ = nil then |
058 | selectedButtonTable [ colorHolder ] .Parent.BackgroundColor = BrickColor.Black() |
060 | guiButton.Parent.BackgroundColor = BrickColor.Yellow() |
061 | colorHolder.BackgroundColor = guiButton.BackgroundColor |
062 | selectionBox.Color = guiButton.BackgroundColor |
063 | selectionLasso.Color = guiButton.BackgroundColor |
064 | Tool.Value.Value = guiButton.BackgroundColor |
065 | selectedButtonTable [ colorHolder ] = guiButton |
067 | onMouseLeavePalette(paletteFrame) |
069 | print ( "Selected Color: " .. guiButton.BackgroundColor.Name) |
072 | function onShowColorDialog(paletteFrame) |
073 | paletteFrame.Visible = true |
076 | function setSelectionBox(part) |
078 | selectionBox.Adornee = part |
079 | selectionLasso.Part = part |
081 | function unsetSelectionBox() |
082 | selectionBox.Adornee = nil |
083 | selectionLasso.Part = nil |
086 | function onMouseEnterGui(mouse) |
091 | function onMouseLeaveGui(mouse) |
095 | function onMouseEnterPalette(mouse) |
100 | function onMouseLeavePalette(paletteFrame, mouse) |
101 | paletteFrame.Visible = false |
106 | local primaryColor = nil |
107 | function buildGui(root, mouse) |
109 | local mainFrame = Instance.new( "Frame" ) |
110 | mainFrame.Position = UDim 2. new( 0.0 , 0 , 1.0 , - 250 ) |
111 | mainFrame.Size = UDim 2. new( 0.0 , 200 , 0.0 , 250 ) |
112 | mainFrame.Transparency = 1.0 |
113 | mainFrame.Parent = root |
116 | local paletteFrame = Instance.new( "Frame" ) |
117 | paletteFrame.Position = UDim 2. new( 0.0 , 0 , 0.0 , 0 ) |
118 | paletteFrame.Size = UDim 2. new( 1.0 , 0 , 4.0 / 5 , 0 ) |
119 | paletteFrame.BackgroundColor = BrickColor.Black() |
120 | paletteFrame.Visible = false |
121 | paletteFrame.Parent = mainFrame |
122 | paletteFrame.MouseEnter:connect( function () print ( "EnterPalette" ) onMouseEnterPalette(mouse) end ) |
123 | paletteFrame.MouseLeave:connect( function () print ( "LeavePalette" ) onMouseLeavePalette(paletteFrame, mouse) end ) |
126 | local sideBar = Instance.new( "Frame" ) |
127 | sideBar.Position = UDim 2. new( 0.0 , 0 , 4.0 / 5 , 0 ) |
128 | sideBar.Size = UDim 2. new( 1.0 , 0 , 1.0 / 5 , 0 ) |
129 | sideBar.BackgroundColor = BrickColor.Black() |
130 | sideBar.Parent = mainFrame |
131 | sideBar.MouseEnter:connect( function () onMouseEnterGui(mouse) end ) |
132 | sideBar.MouseLeave:connect( function () onMouseLeaveGui(mouse) end ) |
134 | primaryColor = Instance.new( "TextButton" ) |
135 | primaryColor.Position = UDim 2. new( 0.75 , 1 , 0.0 , 1 ) |
136 | primaryColor.Size = UDim 2. new( 0.25 , - 2 , 1.0 , - 2 ) |
137 | primaryColor.Text = "" |
138 | primaryColor.BackgroundColor = Tool.Value.Value |
139 | primaryColor.BorderColor = BrickColor.Black() |
140 | primaryColor.BorderSizePixel = 1 |
141 | primaryColor.Parent = sideBar |
142 | primaryColor.MouseButton 1 Down:connect( function () print ( "Showdialog" ) onShowColorDialog(paletteFrame) end ) |
145 | local hoverSelection = Instance.new( "TextLabel" ) |
146 | hoverSelection.Position = UDim 2. new( 0.0 , 0 , 0.0 , 0 ) |
147 | hoverSelection.Size = UDim 2. new( 0.75 , 0 , 1.0 , 0 ) |
148 | hoverSelection.Text = "" |
149 | hoverSelection.BackgroundColor = BrickColor.Black() |
150 | hoverSelection.TextColor = BrickColor.White() |
151 | hoverSelection.Text = primaryColor.BackgroundColor.Name |
152 | hoverSelection.Parent = sideBar |
161 | for xOffset = 0 , 7 do |
163 | local guiFrame = Instance.new( "Frame" ) |
164 | guiFrame.Position = UDim 2. new( 1.0 / 8 * xOffset, 0 , 1.0 / 8 *yOffset, 0 ) |
165 | guiFrame.Size = UDim 2. new( 1.0 / 8 , 0 , 1.0 / 8 , 0 ) |
166 | guiFrame.BackgroundColor = BrickColor.Black() |
167 | guiFrame.BorderSizePixel = 0 |
168 | guiFrame.Parent = paletteFrame |
170 | local guiButton = Instance.new( "TextButton" ) |
171 | guiButton.Position = UDim 2. new( 0.0 , 2 , 0.0 , 2 ) |
172 | guiButton.Size = UDim 2. new( 1.0 , - 4 , 1.0 , - 4 ) |
174 | guiButton.BorderSizePixel = 0 |
175 | guiButton.AutoButtonColor = false |
176 | guiButton.BackgroundColor = BrickColor.palette(xOffset + yOffset* 8 ) |
177 | guiButton.MouseEnter:connect( function () onMouseEnter(hoverSelection, guiButton) end ) |
178 | guiButton.MouseButton 1 Up:connect( function () onMouseUp(primaryColor, paletteFrame, guiButton) end ) |
180 | guiButton.Parent = guiFrame |
182 | if guiButton.BackgroundColor = = primaryColor.BackgroundColor then |
183 | guiFrame.BackgroundColor = BrickColor.White() |
184 | selectedButtonTable [ primaryColor ] = guiButton |
188 | mainFrame.MouseLeave:connect( function () onMouseLeave(hoverSelection) end ) |
191 | function canSelectObject(part) |
192 | return part and not (part.Locked) and (part.Position - Tool.Parent.Head.Position).Magnitude < 60 |
195 | function on 3 dButton 1 Down(mouse) |
196 | local part = mouse.Target |
197 | if canSelectObject(part) then |
198 | if Instance.Lock(part) then |
199 | part.BrickColor = primaryColor.BackgroundColor |
200 | Instance.Unlock(part) |
205 | function on 3 dMouseMove(mouse) |
206 | if not (inGui) and not (inPalette) then |
208 | local part = mouse.Target |
209 | if canSelectObject(part) then |
210 | setSelectionBox(part) |
218 | function onEquippedLocal(mouse) |
221 | local character = script.Parent.Parent |
222 | local player = game.Players:GetPlayerFromCharacter(character) |
224 | guiMain = Instance.new( "ScreenGui" ) |
225 | guiMain.Parent = player.PlayerGui |
230 | mouse.Button 1 Down:connect( function () on 3 dButton 1 Down(mouse) end ) |
231 | mouse.Move:connect( function () on 3 dMouseMove(mouse) end ) |
234 | selectionBox = Instance.new( "SelectionBox" ) |
235 | selectionBox.Color = Tool.Value.Value |
236 | selectionBox.Adornee = nil |
237 | selectionBox.Parent = player.PlayerGui |
239 | selectionLasso = Instance.new( "SelectionPartLasso" ) |
240 | selectionLasso.Name = "Model Delete Lasso" |
241 | selectionLasso.Humanoid = character.Humanoid |
242 | selectionLasso.Part = nil |
243 | selectionLasso.Visible = true |
244 | selectionLasso.archivable = false |
245 | selectionLasso.Color = Tool.Value.Value |
246 | selectionLasso.Parent = game.workspace |
248 | buildGui(guiMain, mouse) |
251 | function onUnequippedLocal() |
252 | Tool.TextureId = origTexture |
254 | selectionBox:Remove() |
255 | selectionLasso:Remove() |
265 | Tool.Equipped:connect(onEquippedLocal) |
266 | Tool.Unequipped:connect(onUnequippedLocal) |