#explain this code

53 messages · Page 1 of 1 (latest)

jaunty eagle
#

explain this code pls ```local part = script.Parent -- Assuming the script is inside the part

local function checkTool(tool)
local mesh = tool:FindFirstChild("Mesh") -- Replace "Mesh" with the name of your mesh
if mesh then
local attribute = mesh:GetAttribute("Color") -- Replace "Attribute" with the name of your attribute
if attribute == "Red" then
part.BrickColor = BrickColor.new("Bright red")
end
end
end

part.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid.CharacterAdded:Connect(function(character)
local backpack = character:WaitForChild("Backpack")
for _, tool in ipairs(backpack:GetChildren()) do
if tool:IsA("Tool") then
checkTool(tool)
end
end
end)
end
end)```

#

anyone explainthsi

rocky path
#

Basically checks if a tool in you in a player’s inventory has the color attribute you decide. And if the the mesh inside of the tool is the one you picked.

jaunty eagle
#

I think you lying

slate snow
#

when the part it touched, it waits for their character to ne added ( which means they will need to die/reset) and then it will get the player's backpack and will check if theres a tool and if there is a tool then it will recolor the tool's part called "Mesh"

thorny ember
#

There is something wrong

#

With the touched function

#

The backpack instance is not located in the character

#

Its located in the player

thorny ember
#

But everything else, gamer8 explained well

jaunty eagle
#

So how can i make it so it instantly gets the players backpack , not after the player dies

thorny ember
#

Just do

#

explain this code pls ```local part = script.Parent -- Assuming the script is inside the part

local function checkTool(tool)
local mesh = tool:FindFirstChild("Mesh") -- Replace "Mesh" with the name of your mesh
if mesh then
local attribute = mesh:GetAttribute("Color") -- Replace "Attribute" with the name of your attribute
if attribute == "Red" then
part.BrickColor = BrickColor.new("Bright red")
end
end
end

part.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
if humanoid then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local backpack = player:WaitForChild("Backpack")
for _, tool in ipairs(backpack:GetChildren()) do
if tool:IsA("Tool") then
checkTool(tool)
end
end)
end
end)```

#

This should work

jaunty eagle
#

Bet

slate snow
jaunty eagle
#

i want it so the part changes color to red when i touch it with the red brush

#

@slate snow

#

help

thorny ember
jaunty eagle
#

what is it doing than

urban lightBOT
#

studio** You are now Level 10! **studio

jaunty eagle
thorny ember
#

Well

#

Its checking when the player touches a part. Then its looking through the players backpack to find a specific tool. Thats it

jaunty eagle
#

but can you pls pls modifite so it check the tools attribute Color and if it equals to Red than the part that it touches turns red

#

pls

#

@thorny ember

thorny ember
#

Explain what you are trying to do

jaunty eagle
#

i am trying to do so when players have the red brush, they can go tocuh the part and the part will change the color to red because its like a quiz and the player has to color the part red

#

@thorny ember

thorny ember
#

Just need to have it

#

Or what

jaunty eagle
#

they need to have it equipped

thorny ember
#

Okay

#

And they need to touch it? Not just click it?

jaunty eagle
#

touch it

#

not click it

thorny ember
#

Okay

#

LOCAL SCRIPT!!

local tool = ["REPLACE_WITH_PATH_TO_TOOL"]
local equipped = false

tool.Equipped:Connect(function()
equipped = true
end)

tool.UnEquipped:Connect(function()
equipped = false
end)

local function onTouch(hit, part)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
If player then
if player == game.Players.LocalPlayer then
local Re = "MAKE A REMOTE EVENT AND REPLACE THIS WITH THE PATH TO THE REMOTE EVENT!"

Re:FireServer(part)
end
end
end

—make a folder and put all the parts that can be touched in the folder. Make this variable the path to the folder:
local folder = ""

while equppied do
for i, v in folder:GetChildren() do
v.Touched:Connect(function(hit)
onTouch(hit, v)
end
end
task.wait()
end
#

SERVER SCRIPT!

local Re = "Remember the remote event you made for the local script? Put the path to it here!"

Re.OnServerEvent:Connect(function(player, part)
part.Color = Color3.fromRGB(255, 0, 0)
end)
#

@jaunty eagle

#

I like your name!

#

@everyone

#

This was not to u

thorny ember
jaunty eagle
#

thanks for the help

jaunty eagle