Hello! I was playing with random scripts because I got bored and confused on why this wasn’t working. I made it in two different ways and none of them worked, they all ended up turning red right when I clicked play. (I know this is a very simple script) It turns red automatically without me touching it.
local function yes()
script.Parent.BrickColor = BrickColor.Red()
end
script.Parent.Touched:Connect(yes)```
----------------------------------------------
local Part = script.Parent
local function yes()
Part.BrickColor = BrickColor.Red()
end
Part.Touched:Connect(yes)
Make sure to set the Anchored property of the part to true, cause Touched relies on physics so it’d fire every time whenever a physics-based part touches it
The problem isn’t it being anchored or not. It’s just that the function they’re connecting doesn’t have a filter so anything that touches it (like I said above) registers the function and changes the color.
That’s only if you want it to include only Players though
Of course if you’d want to get technical, you can use the GetPlayerFromCharacter() function to reference the Player that way & check if a Player did hit that part to change the BrickColor that way
local Part = script.Parent
local function yes(hit)
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
if Player then
Part.BrickColor = BrickColor.new("Bright red")
end
end
Part.Touched:Connect(yes)
Setting the Anchored property to false would make this work too
I know how it works, and that’s typically how people want it, or they want certain parts touching it to activate the function.
The only problem I have with the whole conversation is it seems, to me, like the OP thought that the whole problem with their script was that it needed to be Anchored to work properly. When Anchored/Unanchored was never the problem, just one of many solutions.