What do you want to achieve? I want to make a players part turn purple once a ui is pressed. and yes there is a part i made in the player.
What is the issue?
What solutions have you tried so far? Youtube
Here is my script!
script.Parent.MouseButton1Click:Connect(function(plr)
for i,v in pairs(game.Workspace:GetChildren()) do
if v.Name == plr.Name then
local kids = v:GetChildren()
if kids.Name == "Part" then
v.BrickColor = BrickColor.new(238, 0, 255)
end
end
end
end)
Instead of looping through workspace, you can loop through the character iteself via the localplayer since this is a localscript:
local Player = game:GetService('Players').LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
local Character = Player.Character or Player.CharacterAdded:Wait()
local GetChildren = Character:GetChildren()
for i = 1, #GetChildren do
local Target = GetChildren[i]
if Target:IsA('Part') then
Target.BrickColor = BrickColor.new('Really red')
end
end
end)
Also, BrickColor.new is used for named colors.
Use Color3.fromRBG if you want a range instead, or use BrickColor.new with a color name.
Lastly, MouseButton1Click does not have any arguments.