Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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.

1 comment

0

Thanks

This discussion is preserved as it was. New answers, comments, and votes are closed.