I want the Part to change color to black when I touch it, and pressing E at the same time. But it doesn't work, why?
Mouse = game.Players.LocalPlayer:GetMouse() local Part = script.Parent Part.BrickColor = BrickColor.new("Medium stone grey") Mouse.KeyDown:connect(function(key) if Part.Touched and key == "e" then Part.BrickColor = BrickColor.new("Black") end end)
If it is a normal script, like everyone else was saying, then you can't use LocalPlayer.
Instead, we have to check when a player was added to the game, and take player as a parameter. Also, I recommend changing "key == "e"" to string.lower(key) == "e" as if a player is holding Shift while pressing E, it will not work.
i.e:
game.Players.PlayerAdded:connect(function(player) local Mouse = player:GetMouse() local Part = script.Parent Part.BrickColor = BrickColor.new("Medium stone grey") Mouse.KeyDown:connect(function(key) if Part.Touched and key == "e" then Part.BrickColor = BrickColor.new("Black") end end) end)