Keycode Change System not working?

what i want to achieve is having a changekeycodesystem.

the issue is that this error is shown: Unable to assign property Value. string expected, got Instance i fixed this but now when i want to rebind the keycode it makes the eybind my name D:
scripts: Client:

local us = game:GetService("UserInputService")
local bindedforcepw2 = false
local plr = script.Parent.Parent.Parent
local statss = plr.KeyBinds
local Keys = settingss.KeyBinds
local keypress = script.Parent.KeyPress

-- Define the allowed key codes
local allowedKeyCodes = {
	Enum.KeyCode.F,
	Enum.KeyCode.Q,
	Enum.KeyCode.E,
	Enum.KeyCode.R,
	Enum.KeyCode.T,
	Enum.KeyCode.Y,
	Enum.KeyCode.U,
	Enum.KeyCode.G,
	Enum.KeyCode.H,
	Enum.KeyCode.J,
	Enum.KeyCode.K,
	Enum.KeyCode.N,
	Enum.KeyCode.B,
	Enum.KeyCode.C,
	Enum.KeyCode.X,
	Enum.KeyCode.Z,
}

local function updatetexts()
	Keys.ForcePower1.TextButton.Text = statss.Forcepower1Key.Value
	Keys.ForcePower2.TextButton.Text = statss.Forcepower2Key.Value
	Keys.Dash.TextButton.Text = statss.DashKey.Value
	Keys.TurnOnSaber.TextButton.Text = statss.TurnOn.Value
end

us.InputBegan:Connect(function(input)
	if keypress.Visible then
		if input.UserInputType == Enum.UserInputType.Keyboard then
			local Key = input.KeyCode.Name
			script.ChangeInput:FireServer(Key)
		end
		-- If the loop completes without finding a valid key, nothing changes
	end
end)

Server:

local function disablevalues()
	script.Parent.TurnOnSaber.Value = false
	script.Parent.Dash.Value = false
	script.Parent.Forcepower2.Value = false
	script.Parent.Forcepower1.Value = false
end

script.Parent.ChangeInput.OnServerEvent:Connect(function(Key)
	--Key = tostring(Key)  -- Convert Key to string
	if script.Parent.Forcepower1.Value == true then
		statss.Forcepower2Key.Value = Key
		
		--disablevalues()
	elseif script.Parent.Forcepower2.Value == true then
		statss.Forcepower2Key.Value = Key
		--disablevalues()
	elseif script.Parent.Dash.Value == true then
		statss.DashKey.Value = Key
		--disablevalues()
	elseif script.Parent.TurnOnSaber.Value == true then
		statss.TurnOn.Value = Key
	--	disablevalues()
	end
end)

newer script that i tried as solution that causes the value after rebinding it to be the players name? server stays the same:

local function updatetexts()
    Keys.ForcePower1.TextButton.Text = statss.Forcepower1Key.Value
    Keys.ForcePower2.TextButton.Text = statss.Forcepower2Key.Value
    Keys.Dash.TextButton.Text = statss.DashKey.Value
    Keys.TurnOnSaber.TextButton.Text = statss.TurnOn.Value
end

us.InputBegan:Connect(function(input)
    if keypress.Visible then
        -- Check if the pressed key is in the allowedKeyCodes table
        for _, allowedKeyCode in ipairs(allowedKeyCodes) do
            if input.KeyCode == allowedKeyCode then
                keypress.Visible = false
                updatetexts()
                local Key = tostring(input.KeyCode)
                script.ChangeInput:FireServer(Key)
                return  -- Exit the function once a valid key is found
            end
        end
    end
end)

anybody know how i could fix this and make the values actually be the keys? and not the players name somehow

this happends:
image
shouldnt do that :smiley:

1 Like

When you fire an event from the client it will always send in a “player” value as a parameter. So your key value in the server script is actually the player that pressed the button. The next value would be the key

yes thanks i have found that out, sad that it didnt work how i wanted it too but its alr

1 Like