I have the Roblox paint bucket tool in my game and I want it to detect if the target part is in a model and will paint the children in that model. How should I do this?
( Kinda like Work at a Pizza Place when you paint your house wall.
I have the Roblox paint bucket tool in my game and I want it to detect if the target part is in a model and will paint the children in that model. How should I do this?
( Kinda like Work at a Pizza Place when you paint your house wall.
check if the mouse’s target’s parent is a model (for simplicity I am going to use the mouse object, however i do not recommend you use it as it is deprecated), iterate over all the children of the model, check if they have the brickcolor property, if so, set the brickcolor to desired brickcolor
local mouse = game.Players.LocalPlayer:GetMouse() -- gets localplayer's mouse object
if mouse.Target then -- checks if the mouse even has a target
if mouse.Target.Parent:IsA("Model") then -- checks if target part is a child of a model
for i,v in pairs(mouse.Target.Parent:GetChildren()) do -- iterates over model's children
if v.BrickColor then -- checks if the child has the brickcolor property
v.BrickColor = BrickColor.new(255,0,0) -- sets brickcolor to desired brickcolor (in this case I used red as an example)
end
end
end
end
I’m not sure if this post is a make it for me post, as I’m new to answering on the devforums, so I hope it isn’t
How should I do this? It’s not working
mouse.Button1Up:Connect(function()
if Mouse.Target:FindFirstAncestorWhichIsA("ObjectValue").Value == Player then
if ColorSelection and Mouse.Target:FindFirstChild("Paintable") then
local Data = {Part = Mouse.Target, Color = ColorSelection}
ServerControls:InvokeServer("PaintPart", Data)
PaintSound:Play()
PaintSound.PlaybackSpeed = 0.9 + (math.random() * .1)
if Mouse.Target.Parent:IsA("Model") and Mouse.Target.Parent:FindFirstChild("Paintable") then
isaModel()
end
else
print("Unable to Paint")
end
else
print("Unable to Paint")
end
end)
how come you can do mouse.Button1Up but you can’t do mouse.Target, and instead you use Mouse, they should be the same thing along with the fact I don’t see a definition of Mouse
I’ll change that, but do you have a idea of why it isnt working?
is the object value you’re looking for contained in a model, or a part?, and are you painting just a single part, or all of the parts in the model?
It’s in a folder, and I am wanting it to paint all of the parts in the model.
are there any errors in console?
No, it just doesn’t paint the parts in the model when I click.
can you send the isaModel function?
could you codeblock that? it’s hard to read like this
local function isaModel()
if Mouse.Target.Parent:IsA("Model") and Mouse.Target.Parent:FindFirstChild("Paintable") then
if Mouse and Mouse.Target and ColorSelection then
if Mouse.Target:FindFirstAncestorWhichIsA("ObjectValue").Value == Player then
for i,v in pairs(Mouse.Target.Parent:GetChildren()) do
local Data = {Model = v, Color = ColorSelection}
ServerControls:InvokeServer("PaintModel", Data)
PaintSound:Play()
PaintSound.PlaybackSpeed = 0.9 + (math.random() * .1)
end
end
end
end
end
why would you check if the mouse is nil or if the mouse has a target if you just indexed the mouse with target, then indexed that with Parent, if you index nil with parent it would error before your check, also you might exhaust the remote invokation queue as you are firing the remotefunction for each part, you should probably fire it with Mouse.Target.Parent, and have the server iterate over it’s children