Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why script does not change the part's brickcolor on keypress?

Asked by 5 years ago
Edited 5 years ago
01game.Players.LocalPlayer.CharacterAdded:Wait()
02 
03Player = game:GetService('Players')
04 
05local Character = Player.LocalPlayer.Character
06local Humanoid = Character.Humanoid
07local ContextActionService = game:GetService('ContextActionService')
08 
09local function OnKeyPress()
10    game.Workspace.Part.BrickColor = BrickColor.Random()
11end
12 
13ContextActionService:BindAction("PlayAttac", OnKeyPress, true, 'F')

1 answer

Log in to vote
0
Answered by 5 years ago
01game.Players.LocalPlayer.CharacterAdded:Wait()
02 
03Player = game:GetService('Players')
04 
05local Character = Player.LocalPlayer.Character
06local Humanoid = Character.Humanoid
07local ContextActionService = game:GetService('ContextActionService')
08 
09local function OnKeyPress()
10    game.Workspace.Part.BrickColor = BrickColor.new(math.random(0,255),math.random(0,255),math.random(0,255))
11end
12 
13ContextActionService:BindAction("PlayAttac", OnKeyPress, true, Enum.KeyCode.F)

Use math.random() for the random color and Enum.KeyCode for keys.

0
Thanks wellmoon 0 — 5y
Ad

Answer this question