The way my shop works is there's a large room with the item you can buy. Next to each item is a platform that opens a gui to purchase it. When you press Z, it should buy the item. When you press X, it should close the gui. Z isn't working. Here is my script.

local UserInputService = game:GetService("UserInputService")
local plr = game.Players.LocalPlayer

local function onInputBegan(input, gameProcessed)

    if input.KeyCode == Enum.KeyCode.Z and not gameProcessed then -- added a check for gameprocessed incase they were writing in chat

		if plr.leaderstats.Cash.Value >=20 then
			plr.leaderstats.Cash.Value = plr.leaderstats.Cash.Value - 20
			
			game.ReplicatedStorage.Library.AssaultRifle:Clone().Parent = plr:WaitForChild('Backpack')
		end

    end

end

UserInputService.InputBegan:Connect(onInputBegan)

2 comments

0

Any errors? I do find something that COULD be an issue, the player is buying the tool on the client (I assume since there is LocalPlayer) buying it on the client will not run the function on the server, if the cash saves then it will not count the tool being bought.

0

With my tests I ended up noticing that if I have the gameProcessed it will work and without it it will also work. As yours did not work then I would recommend you to remove the gameProcessed, as in my UserInputService scripts I never put the gameProcessed, I would also recommend you to do the same. Also check that if the script is localScrip and is in StarterPlayerScripts or StarterGui, others.