game.Players.LocalPlayer.CharacterAdded:Wait()
Player = game:GetService('Players')
local Character = Player.LocalPlayer.Character
local Humanoid = Character.Humanoid
local ContextActionService = game:GetService('ContextActionService')
local function OnKeyPress()
game.Workspace.Part.BrickColor = BrickColor.Random()
end
ContextActionService:BindAction("PlayAttac", OnKeyPress, true, 'F')
COMMUNITY QUESTION
Why script does not change the part's brickcolor on keypress?
1 answer
game.Players.LocalPlayer.CharacterAdded:Wait()
Player = game:GetService('Players')
local Character = Player.LocalPlayer.Character
local Humanoid = Character.Humanoid
local ContextActionService = game:GetService('ContextActionService')
local function OnKeyPress()
game.Workspace.Part.BrickColor = BrickColor.new(math.random(0,255),math.random(0,255),math.random(0,255))
end
ContextActionService:BindAction("PlayAttac", OnKeyPress, true, Enum.KeyCode.F)
Use math.random() for the random color and Enum.KeyCode for keys.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Thanks