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 4 years ago
Edited 4 years ago
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')

1 answer

Log in to vote
0
Answered by 4 years ago
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.

0
Thanks wellmoon 0 — 4y
Ad

Answer this question