I;m trying to code out a script that increase the leaderstat "headsize" whenever the u key is pressed and this is what I have so far:
x = 0
function KeyPress(input, gameProcessed)
if input.KeyCode == Enum.KeyCode.U then
x = x + 1
end
end
game:GetService("UserInputService").InputBegan:Connect(KeyPress)
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local headsize = Instance.new("IntValue")
headsize.Name = "headsize"
headsize.Value = x
headsize.Parent = leaderstats
end)
The start works as it starts out with 0, but when I press the U key, nothing happens. I'm sure it's something simple that I'm just blind to, but if you can help me out thanks!

2 comments
is this in one script or two scripts?
This is in one regular script inside of server script service if that helps