How to make a part turn green when a player is touching it and turn it grey when the player is not touching it

i’m trying to do that when a player touch a part(the part is grey) it’s turn green but when the player step out of the part it return grey.

Try this

local Players = game:GetService("Players")

local Part = script.Parent

local TouchingColor = Color3.fromRGB(85, 170, 0)
local NotTouchingColor = Color3.fromRGB(74, 74, 74)

local Touching = false

Part.Touched:Connect(function(Hit)
	if Players:GetPlayerFromCharacter(Hit.Parent) and not Touching then
		Touching = true
		Part.Color = TouchingColor
	end
end)

Part.TouchEnded:Connect(function(Hit)
	if Players:GetPlayerFromCharacter(Hit.Parent) and Touching then
		Touching = false
		Part.Color = NotTouchingColor
	end
end)

it’s work but what if i want that a player touch a not collide part to make an other part change color

So you’re looking for a script that changes a part color when another part is being touched?
If so, I have the script you’re looking for:

--// Variables
local Players = game:GetService("Players") -- Get Players' Service
local Part = game.Workspace.Part -- The part that the player is supposed to touch.
local Part2 = game.Workspace.Part2 -- The part that will change color when the first part is being touched.

--// Part Color Properties
local TouchingColor = Color3.fromRGB(34, 255, 0) -- Color when the part is being touched.
local NotTouchingColor = Color3.fromRGB(74, 74, 74) -- Color when the part is not being touched.

local touched = false

Part.Touched:Connect(function(Hit)
	if Players:GetPlayerFromCharacter(Hit.Parent) and not touched then
		touched = true
		Part2.Color = TouchingColor
	end
end)

Part.TouchEnded:Connect(function(Hit)
	if Players:GetPlayerFromCharacter(Hit.Parent) and touched then
		touched = false
		Part2.Color = NotTouchingColor
	end
end)

I apologize for any grammar error. If you have any errors, tell me, I’ll fix them as soon as possible until you learn and don’t have any more questions.

Credits for 4667Hp for script template? I guess lol

1 Like

already try that the part that i touch is not colide so it’s not working