Updated this Reply! Check the screenshot for the location of the Script.
The script works! However, now it’s messing with the 3rd script within the NPC:
Output error:
Workspace.NPCs.NPC.UpperTorso.RemoveHairScript:2: attempt to index nil with ‘Name’
script.Parent.Touched:Connect(function(Hit)
if Hit.Parent.Name == 'Brush' then
Hit.Parent.Color.Transparency = 1
script.Sound:Play()
wait(2)
script.Parent.Parent:FindFirstChild("Purple").Handle.Transparency = 0
script.Parent.Parent:FindFirstChild("White").Handle.Transparency = 1
wait (35)
script.Parent.Parent:FindFirstChild("Purple").Handle.Transparency = 1
script.Parent.Parent:FindFirstChild("White").Handle.Transparency = 0
end
end)
P.S. I truly appreciate you taking all this time to help me It means a lot!
Here, fixed:
local STARTERPLAYER = game:GetService("StarterPlayer")
local PLAYERS = game:GetService("Players")
local PART_NAME = "Brush"
local SHOULD_BE = true
local PART = script["Parent"]
PART["Touched"]:Connect(function(HIT)
local EQUAL = rawequal(SHOULD_BE, STARTERPLAYER["Dye"]["Value"])
local MATCH = HIT["Parent"]["Name"]:match(PART_NAME)
local NPC = script["Parent"]["Parent"]
local TOOL = HIT["Parent"]
if MATCH and EQUAL then
local PLAYER = PLAYERS:GetPlayerFromCharacter(HIT["Parent"]["Parent"])
local CHARACTER = PLAYER["Character"]
local LEADERSTATS = PLAYER["leaderstats"]
TOOL["Color"]["Transparency"] = 1
script["Sound"]:Play()
CHARACTER[PART_NAME]:Destroy()
LEADERSTATS["Money"]["Value"] += 25
STARTERPLAYER["Dye"]["Value"] = false
task["wait"](2)
NPC:FindFirstChild("Purple")["Handle"]["Transparency"] = 0
NPC:FindFirstChild("White")["Handle"]["Transparency"] = 1
task["wait"](35)
NPC:FindFirstChild("Purple")["Handle"]["Transparency"] = 1
NPC:FindFirstChild("White")["Handle"]["Transparency"] = 0
end
end)
Edit: Screenshot of the Explorer.
Edit 2: Re-wrote the logic, just so it’s a bit more readable.
local STARTERPLAYER = game:GetService("StarterPlayer")
local DYE = STARTERPLAYER:FindFirstChild("Dye")
local PLAYERS = game:GetService("Players")
local NPC = script["Parent"]["Parent"]
local OBJ:{table} = {
[1] = NPC:FindFirstChild("Purple"),
[2] = NPC:FindFirstChild("White")
}
local NAME = "Brush"
local BOOLEAN = true
function TOUCH(...):nil
local PARAMETER:{table} = {...}
local PLAYER = PARAMETER[1]["Parent"]["Parent"]
local TOOL = PARAMETER[1]["Parent"]
local EQUAL:boolean = rawequal(
BOOLEAN,
DYE["Value"]
)
local MATCH:boolean = string["match"](
NAME,
TOOL["Name"]
)
if MATCH and EQUAL then
PLAYER = PLAYERS:GetPlayerFromCharacter(
PLAYER
)
local CHARACTER = PLAYER["Character"]
local LEADERSTATS = PLAYER["leaderstats"]
TOOL["Color"]["Transparency"] = 1
script["Sound"]:Play()
CHARACTER[NAME]:Destroy()
LEADERSTATS["Money"]["Value"] += 25
DYE["Value"] = false
task["wait"](2)
OBJ[1]["Handle"]["Transparency"] = 0
OBJ[2]["Handle"]["Transparency"] = 1
task["wait"](35)
OBJ[1]["Handle"]["Transparency"] = 1
OBJ[2]["Handle"]["Transparency"] = 0
end
end
local PART = script["Parent"]
PART["Touched"]:Connect(TOUCH)
I think I may have corrected it! Let me know what you think—I was guessing this would work:
local STARTERPLAYER = game:GetService("StarterPlayer")
local PLAYERS = game:GetService("Players")
local PART_NAME = "Brush"
local SHOULD_BE = true
local PART = script["Parent"]
PART["Touched"]:Connect(function(HIT)
local MATCH = HIT["Parent"]["Name"]:match(PART_NAME)
local EQUAL = rawequal(SHOULD_BE, STARTERPLAYER["Dye"]["Value"])
if MATCH and EQUAL then
local PLAYER = PLAYERS:GetPlayerFromCharacter(HIT["Parent"]["Parent"])
local CHARACTER = PLAYER["Character"]
local LEADERSTATS = PLAYER["leaderstats"]
local BACKPACK = PLAYER["Backpack"]
CHARACTER[PART_NAME]:Destroy()
LEADERSTATS["Money"]["Value"] += 25
STARTERPLAYER["Dye"]["Value"] = false
script.Sound:Play()
wait(2)
PART["Parent"]:FindFirstChild("Purple").Handle.Transparency = 0
PART["Parent"]:FindFirstChild("White").Handle.Transparency = 1
wait (35)
PART["Parent"]:FindFirstChild("Purple").Handle.Transparency = 1
PART["Parent"]:FindFirstChild("White").Handle.Transparency = 0
end
end)
Yup, you actually did fix it, Nice!
Edit: But it seems like you forgot this part:
If you would like to include that part, you should do that a bit like this because the “Color” instance seems to be inside the tool itself and if you destroyed the tool before, you might have an error.
Wowie! Thank you soooo much for your help! You’re absolutely amazing and I sincerely appreciate your help<3 You put in so much effort and were extremely patient with me I hope to be as awesome as you in the future, I’m gonna follow you!
Ah yes! I see— thanks for pointing that out!