Problem with changing ImageColor3 through script

I have some code that essentially checks whether your pressing some specific keys and when you press each one it should be changing the ImageColor3 of some images to gray but it just isn’t working and I am not sure why. I haven’t really looked around but I have been looking at this for like 30 minutes now and can’t figure out anything, nothing appears in output and there is nothing outlying that could be causing issues.

I store the images I want to change in a variable called uiElements

local uiElements = {
	game:GetService("StarterGui").Stratagems.ScreenGui.StratagemFrame.RIGHT1,  
	game:GetService("StarterGui").Stratagems.ScreenGui.StratagemFrame.RIGHT2,
	game:GetService("StarterGui").Stratagems.ScreenGui.StratagemFrame.UP1
} 

When you click the keybinds (D, D, W) it should change the colour of some arrows to gray

game:GetService("UserInputService").InputBegan:Connect(function(input)
	if input.KeyCode == mainKey then
		holdingMainKey = true
		resetCombo()
	elseif holdingMainKey then
		if isComboKeyPressed(input.KeyCode) then
			for _, uiElement in ipairs(uiElements) do
				uiElement.ImageColor3 = Color3.new(0.505882, 0.505882, 0.505882) 
			end
			currentComboIndex = currentComboIndex + 1
			if currentComboIndex > #comboKeys then
				print("Combo performed!")

image

The arrows its attempting to change

image

Explorer showing the images and LocalScript that is doing all of this

Don’t identify them in StarterGui. To explain, there is a folder named playergui under every player. This copies the startergui pretty much, and allows direct edits of the actual players gui, not just the starter service.

Instead do this,

local player = game.Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local Frame = PlayerGui:WaitForChild("Stratagems"):WaitForChild("ScreenGui"):WaitForChild("StratagemFrame")

local uiElements = {
Frame.RIGHT1,  
	Frame.RIGHT2,
	Frame.UP1
} 

You may notice that I’ve used waitforchild for every GUI class, we do this because GUIs need time to load. They are client properties, and the scripts within them load first, so they won’t identify them.

2 Likes

do you have a part of your code that sets holdingMainKey to false at any point? if you do and it happens on InputEnded, that means it’s impossible for the script to reach the condition elseif holdingMainKey then because every time InputBegan fires it fires with holding as false. InputBegan doesn’t keep firing if you hold the key, it’ll only fire once

1 Like

Thanks, I see what you were getting at and were indeed correct; made some adjustments with the help of the guy above aswell.

Yep this worked, just had to make a few tweaks to make sure it was changing the colour after each keybind click. Thank you!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.