It's because MouseButton1Click doesn't have a parameter, meaning x does not exist and will never be the player that clicked the GUI Button.
To get the player that clicked the button, it's best to switch from normal script to local script then use Players.LocalPlayer.
But wait, there's a problem! You can't access ServerStorage through a local script. You can use ReplicatedStorage to clone your weapon to the player. This is how you would do it.
local ak = game.ReplicatedStorage:WaitForChild("Ak47")
script.Parent.MouseButton1Click:Connect(function()
local clone = ak:Clone()
clone.Parent = game.Players.LocalPlayer.Backpack
end)
But you will notice a problem, you can't damage players with your weapon.
This is how you fix that:
Server script(not local script), place this in ServerScriptService
local ak = game.ReplicatedStorage:WaitForChild("Ak47")
game.ReplicatedStorage:WaitForChild("RemoteEvent").OnServerEvent:Connect(function(plr)
local clone = ak:Clone()
clone.Parent = plr.Backpack
end)
Local Script, place this inside your button
script.Parent.MouseButton1Click:Connect(function()
for i,v in game.Players.LocalPlayer.Backpack:GetChildren() do
if v.Name == "Ak47" then return end
end
game.ReplicatedStorage:WaitForChild("RemoteEvent"):FireServer()
end)