Why is my script not working?

  1. 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.

  2. What is the issue? image

  3. 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)


Color3.new() with a number range of 0 - 1
or in your case
Color3.fromRGB() with a number range of 0 - 255

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.

1 Like

It works, but what does i = 1 mean?

its for i loops here is an article that might help you out
for loops

This is a numerical loop, and will loop through the array (Character:GetChildren()).