Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Script that change color of part if player have a tool in backpack isn't working?

Hello I have a problem why this script isn't working?

game.Players.PlayerAdded:Connect(function(plr)
	local part = script.Parent
	
	while wait(1) do
	
	if plr:FindFirstChild("Backpack") and plr.Character and 
		(plr.Backpack:FindFirstChild("202") or plr.Character:FindFirstChild("202")) then
		
			part.Color = Color3.fromRGB(255,0,0)
	else
			part.Color = Color3.fromRGB(0,255,0)
		
	end
end		
	end)

1 comment

2 answers

Hello, I found 2 problems in the video you listed!

  1. You were removing it from the client and your code runs on the server, which means the on the client you don't have it, but on the server you do so the color won't change!
  2. The tool was called 201 in your video, but in the script it shows 202!

But here's a new script which works a bit better!

Script:

local PlayersService = game:GetService("Players")

PlayersService.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		
		while wait() do
			
			for _, v in pairs(char:GetChildren()) do
				if v and v:IsA("Tool") and v.Name == "202" then
					
					v:FindFirstChild("Handle").Color = Color3.fromRGB(255,0,0)
				else
					v:FindFirstChild("Handle").Color = Color3.fromRGB(0,255,0)
					
				end
			end
			
			for _, v in pairs(player.Backpack:GetChildren()) do
				if v and v:IsA("Tool") and v.Name == "202" then

					v:FindFirstChild("Handle").Color = Color3.fromRGB(255,0,0)
				else
					v:FindFirstChild("Handle").Color = Color3.fromRGB(0,255,0)

				end
			end
			
		end
		
	end)
end)

hey you! have you ever heard of enes? if you are in trouble, better call enes!

This discussion is preserved as it was. New answers, comments, and votes are closed.