Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 2 years ago

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)

2 answers

Log in to vote
0
Answered by
MattVSNNL 620 Moderation Voter
2 years ago
Edited 2 years ago

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)
Ad
Log in to vote
0
Answered by
enes223 327 Moderation Voter
2 years ago

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

Answer this question